Skip to contentSkip to conversation

EDAC/altera: Fix SDMMC PortB OF node reference leak

PATCH Superseded Yuho Choi 2 participants 3 messages May 1 – May 3

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 EDAC/altera: Fix SDMMC PortB OF node reference leak

of_find_compatible_node() returns a device node with its refcount incremented. altr_portb_setup() looks up the SDMMC ECC node but does not drop that reference on error paths or after successful setup.

Route the exits after the lookup through a cleanup path that calls of_node_put() before returning.

Fixes 911049845d70 ("EDAC, altera: Add Arria10 SD-MMC EDAC support")
---
 drivers/edac/altera_edac.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/edac/altera_edac.c +10 -4
index 4edd2088c2db..a2fb30a9b914 100644
@@ -1526,15 +1526,18 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 		edac_printk(KERN_ERR, EDAC_DEVICE,
 			    "%s: Unable to allocate PortB EDAC device\n",
 			    ecc_name);
-		return -ENOMEM;
+		rc = -ENOMEM;
+		goto out_put_node;
 	}
 
 	/* Initialize the PortB EDAC device structure from PortA structure */
 	altdev = dci->pvt_info;
 	*altdev = *device;
 
-	if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL))
-		return -ENOMEM;
+	if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL)) {
+		rc = -ENOMEM;
+		goto out_put_node;
+	}
 
 	/* Update PortB specific values */
 	altdev->edac_dev_name = ecc_name;
@@ -1607,13 +1610,16 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 
 	devres_remove_group(&altdev->ddev, altr_portb_setup);
 
-	return 0;
+	rc = 0;
+	goto out_put_node;
 
 err_release_group_1:
 	edac_device_free_ctl_info(dci);
 	devres_release_group(&altdev->ddev, altr_portb_setup);
 	edac_printk(KERN_ERR, EDAC_DEVICE,
 		    "%s:Error setting up EDAC device: %d\n", ecc_name, rc);
+out_put_node:
+	of_node_put(np);
 	return rc;
 }
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hi Yuho,

Quoted 25 lines · Yuho Choi

of_find_compatible_node() returns a device node with its refcount incremented. altr_portb_setup() looks up the SDMMC ECC node but does not drop that reference on error paths or after successful setup.

Route the exits after the lookup through a cleanup path that calls of_node_put() before returning.

Fixes 911049845d70 ("EDAC, altera: Add Arria10 SD-MMC EDAC support")
---
  drivers/edac/altera_edac.c | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)
drivers/edac/altera_edac.c +2 -1
index 4edd2088c2db..a2fb30a9b914 100644
@@ -1526,15 +1526,18 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
  		edac_printk(KERN_ERR, EDAC_DEVICE,
  			    "%s: Unable to allocate PortB EDAC device\n",
  			    ecc_name);
-		return -ENOMEM;
+		rc = -ENOMEM;
+		goto out_put_node;
  	}

drivers/edac/altera_edac.c static int altr_portb_setup(struct altr_edac_device_dev *device) · line 1539

Quoted 10 lines
drivers/edac/altera_edac.c +3 -2
 
  	/* Initialize the PortB EDAC device structure from PortA structure */
  	altdev = dci->pvt_info;
  	*altdev = *device;
 
-	if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL))
-		return -ENOMEM;
+	if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL)) {
+		rc = -ENOMEM;
+		goto out_put_node;

I think this should goto err_release_group_1, otherwise the dci pointer is leaked.

Dinh

author
#2 lore raw

Dear Dinh,

Thanks for catching that dci leak. I will update the goto path in v2.

Yuho

Quoted 46 lines · Dinh Nguyen

Hi Yuho,

Quoted 25 lines · Yuho Choi

of_find_compatible_node() returns a device node with its refcount incremented. altr_portb_setup() looks up the SDMMC ECC node but does not drop that reference on error paths or after successful setup.

Route the exits after the lookup through a cleanup path that calls of_node_put() before returning.

Fixes 911049845d70 ("EDAC, altera: Add Arria10 SD-MMC EDAC support")
---
  drivers/edac/altera_edac.c | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)
drivers/edac/altera_edac.c +2 -1
index 4edd2088c2db..a2fb30a9b914 100644
@@ -1526,15 +1526,18 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
              edac_printk(KERN_ERR, EDAC_DEVICE,
                          "%s: Unable to allocate PortB EDAC device\n",
                          ecc_name);
-             return -ENOMEM;
+             rc = -ENOMEM;
+             goto out_put_node;
      }

drivers/edac/altera_edac.c static int altr_portb_setup(struct altr_edac_device_dev *device) · line 1539

Quoted 10 lines
drivers/edac/altera_edac.c +3 -2
 
      /* Initialize the PortB EDAC device structure from PortA structure */
      altdev = dci->pvt_info;
      *altdev = *device;
 
-     if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL))
-             return -ENOMEM;
+     if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL)) {
+             rc = -ENOMEM;
+             goto out_put_node;

I think this should goto err_release_group_1, otherwise the dci pointer is leaked.

Dinh