[PATCH 01/10] EDAC/altera: Fix NULL of_node dereference altr_edac_device_probe()

Dinh Nguyen <[email protected]> Mon, 27 Jul 2026 08:24:07 -0500
Newsgroups org.kernel.vger.linux-edac,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
In altr_edac_device_probe() dereferenced pdev->dev.of_node and
of_match_node() before validating it, which could cause a NULL pointer
dereference when the device tree node is missing. Check the result for
a NULL and bail out with -ENODEV before using it.

Assisted-by: Cursor:claude-4.8-opus
Fixes: c3eea1942a16 ("EDAC, altera: Add Altera L2 cache and OCRAM support")
Closes: https://sashiko.dev/#/patchset/20260719211238.589402-1-rosenp%40gmail.com
Cc: [email protected]
Signed-off-by: Dinh Nguyen <[email protected]>
---
 drivers/edac/altera_edac.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/altera_edac.c b/drivers/edac/altera_edac.c
index 68846f583eeef..d6ca68d74f78a 100644
--- a/drivers/edac/altera_edac.c
+++ b/drivers/edac/altera_edac.c
@@ -710,9 +710,18 @@ static int altr_edac_device_probe(struct platform_device *pdev)
 	struct resource *r;
 	int res = 0;
 	struct device_node *np = pdev->dev.of_node;
-	char *ecc_name = (char *)np->name;
+	const struct of_device_id *edac_dev_match;
+	char *ecc_name;
 	static int dev_instance;
 
+	if (!np) {
+		edac_printk(KERN_ERR, EDAC_DEVICE,
+			    "Unable to get device tree node\n");
+		return -ENODEV;
+	}
+
+	ecc_name = (char *)np->name;
+
 	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
 		edac_printk(KERN_ERR, EDAC_DEVICE,
 			    "Unable to open devm\n");
@@ -757,7 +766,14 @@ static int altr_edac_device_probe(struct platform_device *pdev)
 	}
 
 	/* Get driver specific data for this EDAC device */
-	drvdata->data = of_match_node(altr_edac_device_of_match, np)->data;
+	edac_dev_match = of_match_node(altr_edac_device_of_match, np);
+	if (!edac_dev_match) {
+		edac_printk(KERN_ERR, EDAC_DEVICE,
+			    "%s: Unable to match device\n", ecc_name);
+		res = -ENODEV;
+		goto fail1;
+	}
+	drvdata->data = edac_dev_match->data;
 
 	/* Check specific dependencies for the module */
 	if (drvdata->data->setup) {
-- 
2.42.0.411.g813d9a9188