Skip to contentSkip to conversation

EDAC/altera: Address sashiko reviews part 1

PATCH Superseded Dinh Nguyen 2 participants 13 messages Jul 27 – Jul 31

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Dinh Nguyen

author maintainer
#0 lore raw

cover EDAC/altera: Address sashiko reviews part 1

This is the first set of patches addressing sashiko reviews. I've tried to the best of my ability to decipher hallucinations and actually bugs found. There are a few more and I anticipate another series, but I wanted to keep the series small and handle the most critical bugs found first.

The most important patch is in this series is "EDAC/altera: Add suppress_bind_attrs so driver cannot get unbound". Because this driver never tested against bind/unbind, this bug was not observed. Without this patch, an unbind/bind would cause the system to crash.

Thanks,
Dinh

Dinh Nguyen (10):
EDAC/altera: Fix NULL of_node dereference altr_edac_device_probe() EDAC/altera: Fix use-after-free in error paths EDAC/altera: Guard against NULL match data in altr_sdram_probe() EDAC/altera: Fix IRQ domain leak on platform_get_irq() failure EDAC/altera: Fix code leak on dci allocation failure EDAC/altera: Add suppress_bind_attrs so driver cannot get unbound EDAC/altera: Drop __init from ECC setup paths for re-probe safety EDAC/altera: Skip ECC memory init if already initialized EDAC/altera: Detach sb_irq handler when db_irq setup fails EDAC/altera: Fix error cleanup path in altr_edac_device_probe()

 drivers/edac/altera_edac.c | 118 ++++++++++++++++++++++++-------------
 1 file changed, 77 insertions(+), 41 deletions(-)
Signature · 1 line
2.42.0.411.g813d9a9188
author maintainer
#1 lore raw

PATCH 1/10 EDAC/altera: Fix NULL of_node dereference altr_edac_device_probe()

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")
---
 drivers/edac/altera_edac.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/edac/altera_edac.c +18 -2
index 68846f583eeef..d6ca68d74f78a 100644
@@ -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) {
Signature · 1 line
2.42.0.411.g813d9a9188
maintainer
#2 lore raw

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

Quoted 2 lines · Dinh Nguyen

In altr_edac_device_probe() dereferenced pdev->dev.of_node and of_match_node() before validating it,

How did that AI let you fumble that sentence? :-P

Quoted 7 lines

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")

So the AI review for this one here is this one, I think:

"This isn't a bug introduced by this patch, but can np be NULL here if the driver is bound via sysfs?
If a privileged user unbinds and rebinds the driver via sysfs to a platform device that lacks an of_node, pdev->dev.of_node will be NULL, which would cause an unconditional dereference when accessing np->name."

Can that happen?

Have you been able to trigger it?

If so, then the mechanism how this happens should be in the commit message, explaining why this fix is needed and why it is needed now, all of a sudden.

AI is helpful in some cases but I would like us to sanity-check everything it hallucinates pls.

Quoted 11 lines
---
 drivers/edac/altera_edac.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/edac/altera_edac.c +0 -0
index 68846f583eeef..d6ca68d74f78a 100644

drivers/edac/altera_edac.c static int altr_edac_device_probe(struct platform_device *pdev) · line 715

Quoted 7 lines
drivers/edac/altera_edac.c +2 -1
@@ -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;

I know this is not something you should do now but let's pay attention to this:

The preferred ordering of variable declarations at the beginning of a function is reverse fir tree order::

	struct long_struct_name *descriptive_name;
	unsigned long foo, bar;
	unsigned int tmp;
	int ret;

The above is faster to parse than the reverse ordering::

	int ret;
	unsigned int tmp;
	unsigned long foo, bar;
	struct long_struct_name *descriptive_name;

And even more so than random ordering::

	unsigned long foo, bar;
	int ret;
	struct long_struct_name *descriptive_name;
	unsigned int tmp;

drivers/edac/altera_edac.c static int altr_edac_device_probe(struct platform_device *pdev) · line 721

Quoted 5 lines
drivers/edac/altera_edac.c +5 -0
+	if (!np) {
+		edac_printk(KERN_ERR, EDAC_DEVICE,
+			    "Unable to get device tree node\n");
+		return -ENODEV;
+	}

Pls write it like this:

	np = pdev->dev.of_node;
	if (!np)
		...
Quoted 6 lines
drivers/edac/altera_edac.c +3 -0
+
+	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");
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#3 lore raw

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

Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Dinh Nguyen

In altr_edac_device_probe() dereferenced pdev->dev.of_node and of_match_node() before validating it,

How did that AI let you fumble that sentence? :-P

sorry about that...

Quoted 11 lines
Quoted 8 lines

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")

So the AI review for this one here is this one, I think:

Quoted 7 lines

"This isn't a bug introduced by this patch, but can np be NULL here if the driver is bound via sysfs?
If a privileged user unbinds and rebinds the driver via sysfs to a platform device that lacks an of_node, pdev->dev.of_node will be NULL, which would cause an unconditional dereference when accessing np->name."

Can that happen?

I don't think this can ever happen. The SoCFPGA platform is strictly OF enabled, so not having an of_node would be impossible.

Let me rework this down some more. Sorry for the noise!

Dinh

author maintainer
#4 lore raw

PATCH 2/10 EDAC/altera: Fix use-after-free in error paths

In reply to Dinh Nguyen

In both altr_edac_a10_device_add() and altr_portb_setup(), the error path freed dci before releasing the devres group. Since the managed SB/DB IRQ handlers use altdev(dci->pvt_info) as their data, an IRQ firing between freeing dci and unregistering the IRQs could dereference freed memory.

Release the devres group first so the managed IRQs are unregistered before dci is freed.

Assisted-by Cursor:claude-4.8-opus
Fixes 911049845d70 ("EDAC, altera: Add Arria10 SD-MMC EDAC support")
Fixes 588cb03ea208 ("EDAC, altera: Add Arria10 L2 Cache ECC handling")
---
 drivers/edac/altera_edac.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/edac/altera_edac.c +14 -1
index d6ca68d74f78a..34b33298cf86e 100644
@@ -1625,8 +1625,13 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 	return 0;
 
 err_release_group_1:
-	edac_device_free_ctl_info(dci);
+	/*
+	 * Release the devres group first so the managed IRQs are
+	 * unregistered before dci (which contains the IRQ handler's
+	 * data via dci->pvt_info) is freed, avoiding a use-after-free.
+	 */
 	devres_release_group(device->edac->dev, altr_portb_setup);
+	edac_device_free_ctl_info(dci);
 	edac_printk(KERN_ERR, EDAC_DEVICE,
 		    "%s:Error setting up EDAC device: %d\n", ecc_name, rc);
 	return rc;
@@ -2029,9 +2034,17 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac,
 	return 0;
 
 err_release_group1:
+	/*
+	 * Release the devres group first so the managed IRQs are
+	 * unregistered before dci (which contains the IRQ handler's
+	 * data via dci->pvt_info) is freed, avoiding a use-after-free.
+	 */
+	devres_release_group(edac->dev, NULL);
 	edac_device_free_ctl_info(dci);
+	goto err_print;
 err_release_group:
 	devres_release_group(edac->dev, NULL);
+err_print:
 	edac_printk(KERN_ERR, EDAC_DEVICE,
 		    "%s:Error setting up EDAC device: %d\n", ecc_name, rc);
 
Signature · 1 line
2.42.0.411.g813d9a9188
author maintainer
#5 lore raw

PATCH 3/10 EDAC/altera: Guard against NULL match data in altr_sdram_probe()

In reply to Dinh Nguyen

sashiko reports: If a device is manually bound and lacks a valid match entry, of_match_node() or device_get_match_data() could return NULL.

altr_sdram_probe() dereferenced the pointer returned by of_match_node() and device_get_match_data() without checking it, which could cause a NULL pointer dereference when no match data is found. Add a guard that logs an error and returns -ENODEV.

Assisted-by Cursor:claude-4.8-opus
Fixes 143f4a5ac5af ("EDAC, altera: Refactor for Altera CycloneV SoC")
---
 drivers/edac/altera_edac.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/edac/altera_edac.c +4 -0
index 34b33298cf86e..8cbf71ce5d2d8 100644
@@ -300,6 +300,10 @@ static int altr_sdram_probe(struct platform_device *pdev)
 
 	/* Check specific dependencies for the module */
 	priv = device_get_match_data(&pdev->dev);
+	if (!priv) {
+		edac_printk(KERN_ERR, EDAC_MC, "No match data found\n");
+		return -ENODEV;
+	}
 
 	/* Validate the SDRAM controller has ECC enabled */
 	if (regmap_read(mc_vbase, priv->ecc_ctrl_offset, &read_reg) ||
Signature · 1 line
2.42.0.411.g813d9a9188
author maintainer
#6 lore raw

PATCH 4/10 EDAC/altera: Fix IRQ domain leak on platform_get_irq() failure

In reply to Dinh Nguyen

sashiko reports: If platform_get_irq() fails, the function returns without freeing the previously allocated edac->domain.

altr_edac_a10_probe() created an IRQ domain via irq_domain_create_linear() but returned without freeing it when the subsequent platform_get_irq() calls for the SB or DB IRQ failed, leaking the domain. Call irq_domain_remove() before returning on those error paths.

Assisted-by Cursor:claude-4.8-opus
Fixes 13ab8448d2c9 ("EDAC, altera: Add ECC Manager IRQ controller support")
---
 drivers/edac/altera_edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/edac/altera_edac.c +6 -2
index 8cbf71ce5d2d8..e5d225f799f39 100644
@@ -2179,8 +2179,10 @@ static int altr_edac_a10_probe(struct platform_device *pdev)
 	}
 
 	edac->sb_irq = platform_get_irq(pdev, 0);
-	if (edac->sb_irq < 0)
+	if (edac->sb_irq < 0) {
+		irq_domain_remove(edac->domain);
 		return edac->sb_irq;
+	}
 
 	irq_set_chained_handler_and_data(edac->sb_irq,
 					 altr_edac_a10_irq_handler,
@@ -2210,8 +2212,10 @@ static int altr_edac_a10_probe(struct platform_device *pdev)
 		}
 	} else {
 		edac->db_irq = platform_get_irq(pdev, 1);
-		if (edac->db_irq < 0)
+		if (edac->db_irq < 0) {
+			irq_domain_remove(edac->domain);
 			return edac->db_irq;
+		}
 
 		irq_set_chained_handler_and_data(edac->db_irq,
 						 altr_edac_a10_irq_handler, edac);
Signature · 1 line
2.42.0.411.g813d9a9188
author maintainer
#7 lore raw

PATCH 5/10 EDAC/altera: Fix code leak on dci allocation failure

In reply to Dinh Nguyen

sashiko reports: If devres_open_group() fails, the function returns -ENOMEM without freeing the dci structure allocated earlier with edac_device_alloc_ctl_info().

Free the dci structure if devres_open_group() fails.

Fixes c3eea1942a16 ("EDAC, altera: Add Altera L2 cache and OCRAM support")
---
 drivers/edac/altera_edac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/edac/altera_edac.c +3 -1
index e5d225f799f39..09e040b244673 100644
@@ -1554,8 +1554,10 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 	altdev = dci->pvt_info;
 	*altdev = *device;
 
-	if (!devres_open_group(device->edac->dev, altr_portb_setup, GFP_KERNEL))
+	if (!devres_open_group(device->edac->dev, altr_portb_setup, GFP_KERNEL)) {
+		edac_device_free_ctl_info(dci);
 		return -ENOMEM;
+	}
 
 	/* Update PortB specific values */
 	altdev->edac_dev_name = ecc_name;
Signature · 1 line
2.42.0.411.g813d9a9188
author maintainer
#8 lore raw

PATCH 6/10 EDAC/altera: Add suppress_bind_attrs so driver cannot get unbound

In reply to Dinh Nguyen

The EDAC driver should not be able to be removed from userspace because a re-bind would clear out existing memory contents of an active running system.

With this change, remove the .remove functions because they will not ever get called.

Fixes 588cb03ea208 ("EDAC, altera: Add Arria10 L2 Cache ECC handling")
---
 drivers/edac/altera_edac.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)
drivers/edac/altera_edac.c +4 -21
index 09e040b244673..cd2c2d11214d4 100644
@@ -457,15 +457,6 @@ static int altr_sdram_probe(struct platform_device *pdev)
 	return res;
 }
 
-static void altr_sdram_remove(struct platform_device *pdev)
-{
-	struct mem_ctl_info *mci = platform_get_drvdata(pdev);
-
-	edac_mc_del_mc(&pdev->dev);
-	edac_mc_free(mci);
-	platform_set_drvdata(pdev, NULL);
-}
-
 /*
  * If you want to suspend, need to disable EDAC by removing it
  * from the device tree or defconfig.
@@ -485,13 +476,13 @@ static const struct dev_pm_ops altr_sdram_pm_ops = {
 
 static struct platform_driver altr_sdram_edac_driver = {
 	.probe = altr_sdram_probe,
-	.remove = altr_sdram_remove,
 	.driver = {
 		.name = "altr_sdram_edac",
 #ifdef CONFIG_PM
 		.pm = &altr_sdram_pm_ops,
 #endif
 		.of_match_table = altr_sdram_ctrl_of_match,
+		.suppress_bind_attrs = true,
 	},
 };
 
@@ -521,6 +512,7 @@ static struct platform_driver altr_edac_driver = {
 	.driver = {
 		.name = "socfpga_ecc_manager",
 		.of_match_table = altr_edac_of_match,
+		.suppress_bind_attrs = true,
 	},
 };
 module_platform_driver(altr_edac_driver);
@@ -823,22 +815,12 @@ static int altr_edac_device_probe(struct platform_device *pdev)
 	return res;
 }
 
-static void altr_edac_device_remove(struct platform_device *pdev)
-{
-	struct edac_device_ctl_info *dci = platform_get_drvdata(pdev);
-	struct altr_edac_device_dev *drvdata = dci->pvt_info;
-
-	debugfs_remove_recursive(drvdata->debugfs_dir);
-	edac_device_del_device(&pdev->dev);
-	edac_device_free_ctl_info(dci);
-}
-
 static struct platform_driver altr_edac_device_driver = {
 	.probe =  altr_edac_device_probe,
-	.remove = altr_edac_device_remove,
 	.driver = {
 		.name = "altr_edac_device",
 		.of_match_table = altr_edac_device_of_match,
+		.suppress_bind_attrs = true,
 	},
 };
 module_platform_driver(altr_edac_device_driver);
@@ -2253,6 +2235,7 @@ static struct platform_driver altr_edac_a10_driver = {
 	.driver = {
 		.name = "socfpga_a10_ecc_manager",
 		.of_match_table = altr_edac_a10_of_match,
+		.suppress_bind_attrs = true,
 	},
 };
 module_platform_driver(altr_edac_a10_driver);
Signature · 1 line
2.42.0.411.g813d9a9188
author maintainer
#9 lore raw

PATCH 7/10 EDAC/altera: Drop __init from ECC setup paths for re-probe safety

In reply to Dinh Nguyen

sashiko reports: Does suppressing sysfs unbinding fully prevent the execution of freed __init memory? If altr_sysmgr_regmap_lookup_by_phandle() returns -EPROBE_DEFER, the probe is deferred until after __init memory is freed.

The a10 EDAC .setup callbacks (sdmmc, ethernet, nand, dma, usb, qspi) and their helpers (altr_init_a10_ecc_device_type, altr_init_a10_ecc_block) were marked __init. These run from the probe path, which may execute after init memory is freed -- e.g. a probe deferred via -EPROBE_DEFER that only succeeds once a late/module dependency appears, or a manual unbind/rebind. Calling __init code then dereferences freed memory. Remove __init so these functions remain valid at runtime.

Assisted-by Cursor:claude-4.8-opus
Fixes 788586efd116 ("EDAC/altera: Initialize peripheral FIFOs in probe())
---
 drivers/edac/altera_edac.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/edac/altera_edac.c +8 -8
index cd2c2d11214d4..d8d2adc9c39ac 100644
@@ -946,7 +946,7 @@ static int __maybe_unused altr_init_memory_port(void __iomem *ioaddr, int port)
 	return ret;
 }
 
-static __init int __maybe_unused
+static int __maybe_unused
 altr_init_a10_ecc_block(struct device_node *np, u32 irq_mask,
 			u32 ecc_ctrl_en_mask, bool dual_port)
 {
@@ -1021,7 +1021,7 @@ altr_init_a10_ecc_block(struct device_node *np, u32 irq_mask,
 
 static int validate_parent_available(struct device_node *np);
 static const struct of_device_id altr_edac_a10_device_of_match[];
-static int __init __maybe_unused altr_init_a10_ecc_device_type(char *compat)
+static int __maybe_unused altr_init_a10_ecc_device_type(char *compat)
 {
 	int irq;
 	struct device_node *child, *np;
@@ -1350,7 +1350,7 @@ static const struct edac_device_prv_data a10_l2ecc_data = {
 
 #ifdef CONFIG_EDAC_ALTERA_ETHERNET
 
-static int __init socfpga_init_ethernet_ecc(struct altr_edac_device_dev *dev)
+static int socfpga_init_ethernet_ecc(struct altr_edac_device_dev *dev)
 {
 	int ret;
 
@@ -1380,7 +1380,7 @@ static const struct edac_device_prv_data a10_enetecc_data = {
 
 #ifdef CONFIG_EDAC_ALTERA_NAND
 
-static int __init socfpga_init_nand_ecc(struct altr_edac_device_dev *device)
+static int socfpga_init_nand_ecc(struct altr_edac_device_dev *device)
 {
 	int ret;
 
@@ -1410,7 +1410,7 @@ static const struct edac_device_prv_data a10_nandecc_data = {
 
 #ifdef CONFIG_EDAC_ALTERA_DMA
 
-static int __init socfpga_init_dma_ecc(struct altr_edac_device_dev *device)
+static int socfpga_init_dma_ecc(struct altr_edac_device_dev *device)
 {
 	int ret;
 
@@ -1440,7 +1440,7 @@ static const struct edac_device_prv_data a10_dmaecc_data = {
 
 #ifdef CONFIG_EDAC_ALTERA_USB
 
-static int __init socfpga_init_usb_ecc(struct altr_edac_device_dev *device)
+static int socfpga_init_usb_ecc(struct altr_edac_device_dev *device)
 {
 	int ret;
 
@@ -1470,7 +1470,7 @@ static const struct edac_device_prv_data a10_usbecc_data = {
 
 #ifdef CONFIG_EDAC_ALTERA_QSPI
 
-static int __init socfpga_init_qspi_ecc(struct altr_edac_device_dev *device)
+static int socfpga_init_qspi_ecc(struct altr_edac_device_dev *device)
 {
 	int ret;
 
@@ -1625,7 +1625,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 	return rc;
 }
 
-static int __init socfpga_init_sdmmc_ecc(struct altr_edac_device_dev *device)
+static int socfpga_init_sdmmc_ecc(struct altr_edac_device_dev *device)
 {
 	int rc = -ENODEV;
 	struct device_node *child;
Signature · 1 line
2.42.0.411.g813d9a9188
author maintainer
#10 lore raw

PATCH 8/10 EDAC/altera: Skip ECC memory init if already initialized

In reply to Dinh Nguyen

altr_init_memory_port() unconditionally triggered the HW memory-init block, which clears the entire memory and ECC data. On a re-probe (e.g. a probe deferred via -EPROBE_DEFER that only succeeds after the protected peripheral is active, or a rebind) this would wipe live peripheral memory. Skip the destructive init when the INITCOMPLETE status bit is already set, so it runs only once.

Assisted-by Cursor:claude-4.8-opus
Fixes 1166fde93d5b ("EDAC, altera: Add Arria10 ECC memory init functions")
---
 drivers/edac/altera_edac.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/edac/altera_edac.c +12 -0
index d8d2adc9c39ac..5087aa5ae5612 100644
@@ -930,6 +930,18 @@ static int __maybe_unused altr_init_memory_port(void __iomem *ioaddr, int port)
 		clear_mask = ALTR_A10_ECC_ERRPENA_MASK;
 	}
 
+	/*
+	 * The HW init block clears the entire memory and ECC data, so only
+	 * run it once. If initialization already completed (e.g. on an
+	 * earlier probe or in the bootloader), skip it so a re-probe caused
+	 * by deferred probing or a rebind does not wipe an active peripheral.
+	 */
+	if (ecc_test_bits(stat_mask, (ioaddr + ALTR_A10_ECC_INITSTAT_OFST))) {
+		/* Clear any pending ECC interrupts */
+		writel(clear_mask, (ioaddr + ALTR_A10_ECC_INTSTAT_OFST));
+		return 0;
+	}
+
 	ecc_set_bits(init_mask, (ioaddr + ALTR_A10_ECC_CTRL_OFST));
 	while (limit--) {
 		if (ecc_test_bits(stat_mask,
Signature · 1 line
2.42.0.411.g813d9a9188
author maintainer
#11 lore raw

PATCH 9/10 EDAC/altera: Detach sb_irq handler when db_irq setup fails

In reply to Dinh Nguyen

altr_edac_a10_probe() installs the sb_irq chained handler before fetching db_irq. If platform_get_irq() for db_irq fails, the probe returned without detaching the sb_irq handler, leaving it pointing at the devm-freed edac struct. Unlink the sb_irq chained handler before removing the IRQ domain and returning.

Assisted-by Cursor:claude-4.8-opus
Fixes d5fc9125566c ("EDAC, altera: Combine Stratix10 and Arria10 probe functions")
---
 drivers/edac/altera_edac.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/edac/altera_edac.c +2 -0
index 5087aa5ae5612..80ca9f511ac98 100644
@@ -2209,6 +2209,8 @@ static int altr_edac_a10_probe(struct platform_device *pdev)
 	} else {
 		edac->db_irq = platform_get_irq(pdev, 1);
 		if (edac->db_irq < 0) {
+			irq_set_chained_handler_and_data(edac->sb_irq,
+							 NULL, NULL);
 			irq_domain_remove(edac->domain);
 			return edac->db_irq;
 		}
Signature · 1 line
2.42.0.411.g813d9a9188
author maintainer
#12 lore raw

PATCH 10/10 EDAC/altera: Fix error cleanup path in altr_edac_device_probe()

In reply to Dinh Nguyen

sashiko reports: Does the error cleanup path in altr_edac_device_probe() free data before unregistering the interrupt handler? If a failure occurs, dci is explicitly freed via edac_device_free_ctl_info(dci) before the managed IRQ handler is unregistered via devres_release_group(). If an interrupt fires in this window, could it dereference the freed dci?

Clean up the fail1 path to always call devres_release_group() and conditionally free the dci.

Fixes c3eea1942a16 ("EDAC, altera: Add Altera L2 cache and OCRAM support")
---
 drivers/edac/altera_edac.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/edac/altera_edac.c +6 -6
index 80ca9f511ac98..b6048a1884f43 100644
@@ -701,7 +701,7 @@ MODULE_DEVICE_TABLE(of, altr_edac_device_of_match);
  */
 static int altr_edac_device_probe(struct platform_device *pdev)
 {
-	struct edac_device_ctl_info *dci;
+	struct edac_device_ctl_info *dci = NULL;
 	struct altr_edac_device_dev *drvdata;
 	struct resource *r;
 	int res = 0;
@@ -729,7 +729,7 @@ static int altr_edac_device_probe(struct platform_device *pdev)
 		edac_printk(KERN_ERR, EDAC_DEVICE,
 			    "Unable to get mem resource\n");
 		res = -ENODEV;
-		goto fail;
+		goto fail1;
 	}
 
 	if (!devm_request_mem_region(&pdev->dev, r->start, resource_size(r),
@@ -737,7 +737,7 @@ static int altr_edac_device_probe(struct platform_device *pdev)
 		edac_printk(KERN_ERR, EDAC_DEVICE,
 			    "%s:Error requesting mem region\n", ecc_name);
 		res = -EBUSY;
-		goto fail;
+		goto fail1;
 	}
 
 	dci = edac_device_alloc_ctl_info(sizeof(*drvdata), ecc_name,
@@ -747,7 +747,7 @@ static int altr_edac_device_probe(struct platform_device *pdev)
 		edac_printk(KERN_ERR, EDAC_DEVICE,
 			    "%s: Unable to allocate EDAC device\n", ecc_name);
 		res = -ENOMEM;
-		goto fail;
+		goto fail1;
 	}
 
 	drvdata = dci->pvt_info;
@@ -806,9 +806,9 @@ static int altr_edac_device_probe(struct platform_device *pdev)
 	return 0;
 
 fail1:
-	edac_device_free_ctl_info(dci);
-fail:
 	devres_release_group(&pdev->dev, NULL);
+	if (dci)
+		edac_device_free_ctl_info(dci);
 	edac_printk(KERN_ERR, EDAC_DEVICE,
 		    "%s:Error setting up EDAC device: %d\n", ecc_name, res);
 
Signature · 1 line
2.42.0.411.g813d9a9188