Skip to contentSkip to conversation

EDAC/altera: Address sashiko reviews part 1(v5)

PATCH In review Dinh Nguyen 2 participants 10 messages Sep 11 – Sep 26

Subsystems (3)
lore
Share & tools
lore

Dinh Nguyen

author maintainer
#0 lore raw

v5 cover EDAC/altera: Address sashiko reviews part 1(v5)

Hi EDAC maintainers,

This is version 5 of the patch series that addresses some of the sashiko reviews for the Altera EDAC driver.

Here's what changed:

v5: Fix a missing } in patch 3/4

v4: Rebased the series to edac-urgent branch because of patch 9868f5c077df ("EDAC/altera: Use parent device for devres in altr_portb_setup()") will cause conflicts.

v3: simplified commit message based on Borislav's comments

v2: reworked to only includ true sashiko hits

Thanks,
Dinh

Dinh Nguyen (4):
EDAC/altera: Do not allow driver unbinding EDAC/altera: Drop __init from ECC setup paths for re-probe safety EDAC/altera: Fix code leak on dci allocation failure EDAC/altera: Fix use-after-free in error paths

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

PATCH v5 1/4 EDAC/altera: Do not allow driver unbinding

The EDAC driver must remain bound; unbinding and re-binding it would erase active system memory.

Remove the .remove functions because they will not ever get used.

Fixes 588cb03ea208 ("EDAC, altera: Add Arria10 L2 Cache ECC handling")

---
v5: no changes
v4: rebased to edac-urgent
v3: simplify commit messsage
v2: reworked v1 to include only true sashiko hits

---
 drivers/edac/altera_edac.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)
drivers/edac/altera_edac.c +4 -21
index 68846f583eeef..fe501c89dd0dc 100644
@@ -453,15 +453,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.
@@ -481,13 +472,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,
 	},
 };
 
@@ -517,6 +508,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);
@@ -803,22 +795,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);
@@ -2214,6 +2196,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
#2 lore raw

PATCH v5 2/4 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()")

---
v4: rebased to edac-urgent
v3: no changes
v2: reworked v1 to include only true sashiko hits

---
 drivers/edac/altera_edac.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/edac/altera_edac.c +8 -8
index fe501c89dd0dc..d8a3438fb5f44 100644
@@ -926,7 +926,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)
 {
@@ -1001,7 +1001,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;
@@ -1330,7 +1330,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;
 
@@ -1360,7 +1360,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;
 
@@ -1390,7 +1390,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;
 
@@ -1420,7 +1420,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;
 
@@ -1450,7 +1450,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;
 
@@ -1598,7 +1598,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
#3 lore raw

PATCH v5 3/4 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")

---
v5: add missing } to fix build
v4: rebased to edac-urgent
v3: No changes
v2: reworked v1 to include only true sashiko hits

---
 drivers/edac/altera_edac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/edac/altera_edac.c +3 -1
index d8a3438fb5f44..ccdfb35178b69 100644
@@ -1516,8 +1516,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
#4 lore raw

PATCH v5 4/4 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 the dci structure before releasing the devres group. Since the managed single and double bit IRQ handlers use altdev(dci->pvt_info) as their data, an IRQ firing between freeing dci and unregistering the IRQs could dereference the freed memory.

Release the devres group first so the managed IRQs are unregistered before the dci structure 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")

---
v5: No changes
v4: rebased to edac-urgent
v3: No changes
v2: reworked v1 to include only true sashiko hits

---
 drivers/edac/altera_edac.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/edac/altera_edac.c +14 -1
index ccdfb35178b69..4c20fb9261608 100644
@@ -1593,8 +1593,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;
@@ -1997,9 +2002,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
In reply to Dinh Nguyen

Ping on this series. Just wondering if there any comments for this series? From Boris's comments on V2[1], I thought the series is ready.

Thanks,
Dinh

[1] https://lore.kernel.org/all/20260814021511.GBan56L1fI-AhQ1g39@fat_crate.local/

Quoted 29 lines · Dinh Nguyen

Hi EDAC maintainers,

This is version 5 of the patch series that addresses some of the sashiko reviews for the Altera EDAC driver.

Here's what changed:

v5: Fix a missing } in patch 3/4

v4: Rebased the series to edac-urgent branch because of patch 9868f5c077df ("EDAC/altera: Use parent device for devres in altr_portb_setup()") will cause conflicts.

v3: simplified commit message based on Borislav's comments

v2: reworked to only includ true sashiko hits

Thanks,
Dinh

Dinh Nguyen (4):
EDAC/altera: Do not allow driver unbinding EDAC/altera: Drop __init from ECC setup paths for re-probe safety EDAC/altera: Fix code leak on dci allocation failure EDAC/altera: Fix use-after-free in error paths

  drivers/edac/altera_edac.c | 60 ++++++++++++++++++--------------------
  1 file changed, 29 insertions(+), 31 deletions(-)
maintainer
#6 lore raw
Quoted 2 lines · Dinh Nguyen

Ping on this series. Just wondering if there any comments for this series? From Boris's comments on V2[1], I thought the series is ready.

They're on the todo list.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#7 lore raw
In reply to Dinh Nguyen
Quoted 5 lines · Dinh Nguyen

Dinh Nguyen (4):
EDAC/altera: Do not allow driver unbinding EDAC/altera: Drop __init from ECC setup paths for re-probe safety EDAC/altera: Fix code leak on dci allocation failure EDAC/altera: Fix use-after-free in error paths

All those are marked for stable backports but the last three are fixing error handling paths. Are they really that serious that you want to backport them everywhere? If so, which ones?

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#8 lore raw
Quoted 11 lines · Borislav Petkov
Quoted 5 lines · Dinh Nguyen

Dinh Nguyen (4):
EDAC/altera: Do not allow driver unbinding EDAC/altera: Drop __init from ECC setup paths for re-probe safety EDAC/altera: Fix code leak on dci allocation failure EDAC/altera: Fix use-after-free in error paths

All those are marked for stable backports but the last three are fixing error handling paths. Are they really that serious that you want to backport them everywhere? If so, which ones?

All patches should be applied to v6.18+. Would you like me to follow up with a v6 that has the proper tag for v6.18+?

Dinh

maintainer
#9 lore raw
Quoted 2 lines · Dinh Nguyen

All patches should be applied to v6.18+. Would you like me to follow up with a v6 that has the proper tag for v6.18+?

Nope, all fixed and pushed out. It'll go to Linus in a week or so.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette