drivers: Fix reference leak in altr_sysmgr_regmap_lookup_by_phandle()
Subsystems (2)
PATCH 1/1 drivers: Fix reference leak in altr_sysmgr_regmap_lookup_by_phandle()
altr_sysmgr_regmap_lookup_by_phandle() utilizes driver_find_device_by_of_node() which internally calls driver_find_device() to locate the matching device. driver_find_device() increments the ref count of the found device by calling get_device(), but altr_sysmgr_regmap_lookup_by_phandle() fails to call put_device() to decrement the reference count before returning. This results in a reference count leak of the device, which may prevent the device from being properly released and cause a memory leak.
Found by code review.
--- drivers/mfd/altera-sysmgr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mfd/altera-sysmgr.c +4 -1
@@ -98,6 +98,7 @@ struct regmap *altr_sysmgr_regmap_lookup_by_phandle(struct device_node *np,struct device *dev;struct altr_sysmgr *sysmgr;struct device_node *sysmgr_np; +struct regmap *regmap;if (property) sysmgr_np =of_parse_phandle (np, property,0 );
@@ -116,8 +117,10 @@ struct regmap *altr_sysmgr_regmap_lookup_by_phandle(struct device_node *np,return ERR_PTR (-EPROBE_DEFER ); sysmgr =dev_get_drvdata (dev); + regmap = sysmgr->regmap; +put_device (dev); -return sysmgr->regmap; +return regmap; }EXPORT_SYMBOL_GPL (altr_sysmgr_regmap_lookup_by_phandle);
Signature · 1 line
2.17.1
…
Quoted 1 line
Found by code review.
See also the commit facd37d3882baad4a38afdd5f33908f6fc145d13
("mfd: altera-sysmgr: Fix device leak on sysmgr regmap lookup") from 2025-10-21.
Regards,
Markus
Lee Jones
maintainerQuoted 5 lines · Markus Elfring
…
Quoted 1 line
Found by code review.
See also the commit
facd37d3882baad4a38afdd5f33908f6fc145d13
("mfd: altera-sysmgr: Fix device leak on sysmgr regmap lookup") from 2025-10-21.
This patch has the correct formatting and doesn't do extra, unnecessary actions like store the regmap into a local variable for some unexplained reason. For those reasons, I'm planning on taking this one instead.
Signature · 1 line
Lee Jones [李琼斯]