Skip to contentSkip to conversation

mfd: altera-sysmgr: Fix device reference leak in altr_sysmgr_regmap_lookup_by_phandle

PATCH In review Miaoqian Lin 2 participants 2 messages Oct 28, 2025 – Nov 6, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mfd: altera-sysmgr: Fix device reference leak in altr_sysmgr_regmap_lookup_by_phandle

driver_find_device_by_of_node() calls driver_find_device(), which calls get_device(). get_device() increments the device's reference count, so driver_find_device_by_of_node() returns a device
with its reference count incremented.
We need to release this reference after usage to avoid a reference leak.

Add put_device(dev) after dev_get_drvdata() to fix the reference leak.

Found via static analysis.

Fixes f36e789a1f8d ("mfd: altera-sysmgr: Add SOCFPGA System Manager")
---
 drivers/mfd/altera-sysmgr.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mfd/altera-sysmgr.c +1 -0
index fb5f988e61f3..cb66b2fff536 100644
@@ -116,6 +116,7 @@ struct regmap *altr_sysmgr_regmap_lookup_by_phandle(struct device_node *np,
 		return ERR_PTR(-EPROBE_DEFER);
 
 	sysmgr = dev_get_drvdata(dev);
+	put_device(dev);
 
 	return sysmgr->regmap;
 }
Signature · 1 line
2.39.5 (Apple Git-154)
maintainer
#1 lore raw
Quoted 6 lines · Miaoqian Lin

driver_find_device_by_of_node() calls driver_find_device(), which calls get_device(). get_device() increments the device's reference count, so driver_find_device_by_of_node() returns a device
with its reference count incremented.
We need to release this reference after usage to avoid a reference leak.

Quoted 7 lines

Add put_device(dev) after dev_get_drvdata() to fix the reference leak.

Found via static analysis.

Fixes f36e789a1f8d ("mfd: altera-sysmgr: Add SOCFPGA System Manager")

Looks like Johan beat you to it.

Signature · 1 line
Lee Jones [李琼斯]