Skip to contentSkip to conversation

EDAC/altera: Fix device node reference leaks in the SDMMC ECC setup

PATCH Applied Rounak Das 2 participants 3 messages Sep 26

Subsystems (3)
lore
Share & tools
lore

Rounak Das

author
#0 lore raw

PATCH v3 1/1 EDAC/altera: Fix device node reference leaks in the SDMMC ECC setup

Under altr_portb_setup() and socfpga_init_sdmmc_ecc(), of_find_compatible_node() was being used to look up the sdmmc-ecc node. This node wasn't being dropped using of_node_put().

altr_portb_setup() did not drop its reference under its success path or on any error path.

socfpga_init_sdmmc_ecc() did an early return thereby skipping the common exit label and thus leaking the reference.

Add the missing of_node_put() calls in altr_portb_setup(), and route socfpga_init_sdmmc_ecc()'s success path through the common exit label.

Fixes 911049845d70 ("EDAC, altera: Add Arria10 SD-MMC EDAC support")
Fixes 788586efd116 ("EDAC/altera: Initialize peripheral FIFOs in probe()")

---
v3:
- Rebase on top of Dinh's "Address sashiko reviews part 1" series (Dinh).
- Limit stable backport to 6.18+.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 drivers/edac/altera_edac.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/edac/altera_edac.c +6 -1
index 4c20fb926160..bb95dab847b3 100644
@@ -1506,6 +1506,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 	dci = edac_device_alloc_ctl_info(sizeof(*altdev), ecc_name, 1,
 					 ecc_name, 1, 0, edac_idx);
 	if (!dci) {
+		of_node_put(np);
 		edac_printk(KERN_ERR, EDAC_DEVICE,
 			    "%s: Unable to allocate PortB EDAC device\n",
 			    ecc_name);
@@ -1518,6 +1519,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 
 	if (!devres_open_group(device->edac->dev, altr_portb_setup, GFP_KERNEL)) {
 		edac_device_free_ctl_info(dci);
+		of_node_put(np);
 		return -ENOMEM;
 	}
 
@@ -1584,6 +1586,8 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 		rc = -ENOMEM;
 		goto err_release_group_1;
 	}
+	of_node_put(np);
+
 	altr_create_edacdev_dbgfs(dci, prv);
 
 	list_add(&altdev->next, &altdev->edac->a10_ecc_devices);
@@ -1600,6 +1604,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 	 */
 	devres_release_group(device->edac->dev, altr_portb_setup);
 	edac_device_free_ctl_info(dci);
+	of_node_put(np);
 	edac_printk(KERN_ERR, EDAC_DEVICE,
 		    "%s:Error setting up EDAC device: %d\n", ecc_name, rc);
 	return rc;
@@ -1627,7 +1632,7 @@ static int socfpga_init_sdmmc_ecc(struct altr_edac_device_dev *device)
 		goto exit;
 
 	/* Setup portB */
-	return altr_portb_setup(device);
+	rc = altr_portb_setup(device);
 
 exit:
 	of_node_put(child);

base-commit: eef3b67f9c6782127163b631c9043011a68016e2

Signature · 1 line
2.54.0 (Apple Git-157)
maintainer Applied
#1 lore raw
Quoted 25 lines · Rounak Das

Under altr_portb_setup() and socfpga_init_sdmmc_ecc(), of_find_compatible_node() was being used to look up the sdmmc-ecc node. This node wasn't being dropped using of_node_put().

altr_portb_setup() did not drop its reference under its success path or on any error path.

socfpga_init_sdmmc_ecc() did an early return thereby skipping the common exit label and thus leaking the reference.

Add the missing of_node_put() calls in altr_portb_setup(), and route socfpga_init_sdmmc_ecc()'s success path through the common exit label.

Fixes 911049845d70 ("EDAC, altera: Add Arria10 SD-MMC EDAC support")
Fixes 788586efd116 ("EDAC/altera: Initialize peripheral FIFOs in probe()")

---
v3:
- Rebase on top of Dinh's "Address sashiko reviews part 1" series (Dinh).
- Limit stable backport to 6.18+.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Quoted 3 lines
---
 drivers/edac/altera_edac.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Applied, thanks.

Btw, Dinh, that altr_portb_setup() needs proper scrubbing and reworking of the error handling into using proper goto labels. Otherwise, there'll be more sprinkling of unwinding functions like in this patch everywhere and this'll turn into a real nightmare soon.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

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

Hi Dinh,

If you have not started on it yet, I would like to take up reworking the error handling in altr_portb_setup() into proper goto labels.

Thanks,
Rounak