Skip to contentSkip to conversation

EDAC/altera: fix refcount leak in altr_portb_setup()

PATCH New Wang Yufen 1 participant 1 message Dec 14, 2022

Subsystems (2)
lore
Share & tools
lore

Wang Yufen

author
#0 lore raw

PATCH 1/1 EDAC/altera: fix refcount leak in altr_portb_setup()

The node returned by of_find_compatible_node() with refcount incremented, of_node_put() needs be called when finish using it. So add it in the error path in altr_portb_setup() and the end of altr_portb_setup().

Fixes 911049845d70 ("EDAC, altera: Add Arria10 SD-MMC EDAC support")
---
 drivers/edac/altera_edac.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/edac/altera_edac.c +6 -1
index e7e8e62..3d79fd3 100644
@@ -1528,6 +1528,7 @@ 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);
+		of_node_put(np);
 		return -ENOMEM;
 	}
 
@@ -1535,8 +1536,10 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 	altdev = dci->pvt_info;
 	*altdev = *device;
 
-	if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL))
+	if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL)) {
+		of_node_put(np);
 		return -ENOMEM;
+	}
 
 	/* Update PortB specific values */
 	altdev->edac_dev_name = ecc_name;
@@ -1611,9 +1614,11 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
 
 	devres_remove_group(&altdev->ddev, altr_portb_setup);
 
+	of_node_put(np);
 	return 0;
 
 err_release_group_1:
+	of_node_put(np);
 	edac_device_free_ctl_info(dci);
 	devres_release_group(&altdev->ddev, altr_portb_setup);
 	edac_printk(KERN_ERR, EDAC_DEVICE,
Signature · 1 line
1.8.3.1