* [PATCH] drivers: Fix reference leak in altr_sysmgr_regmap_lookup_by_phandle()
@ 2025-10-25 14:23 Ma Ke
2025-10-25 20:13 ` Markus Elfring
0 siblings, 1 reply; 3+ messages in thread
From: Ma Ke @ 2025-10-25 14:23 UTC (permalink / raw)
To: lee, suzuki.poulose, broonie, mdf, wsa; +Cc: linux-kernel, akpm, Ma Ke, stable
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.
Cc: stable@vger.kernel.org
Fixes: cfba5de9b99f ("drivers: Introduce device lookup variants by of_node")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/mfd/altera-sysmgr.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
index fb5f988e61f3..c6c763fb7bbe 100644
--- a/drivers/mfd/altera-sysmgr.c
+++ b/drivers/mfd/altera-sysmgr.c
@@ -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);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] drivers: Fix reference leak in altr_sysmgr_regmap_lookup_by_phandle()
2025-10-25 14:23 [PATCH] drivers: Fix reference leak in altr_sysmgr_regmap_lookup_by_phandle() Ma Ke
@ 2025-10-25 20:13 ` Markus Elfring
2025-11-06 14:39 ` Lee Jones
0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2025-10-25 20:13 UTC (permalink / raw)
To: make24, mdf
Cc: stable, LKML, Andrew Morton, Johan Hovold, Lee Jones, Mark Brown,
Suzuki Poulouse, Wolfram Sang
…
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] drivers: Fix reference leak in altr_sysmgr_regmap_lookup_by_phandle()
2025-10-25 20:13 ` Markus Elfring
@ 2025-11-06 14:39 ` Lee Jones
0 siblings, 0 replies; 3+ messages in thread
From: Lee Jones @ 2025-11-06 14:39 UTC (permalink / raw)
To: Markus Elfring
Cc: make24, mdf, stable, LKML, Andrew Morton, Johan Hovold,
Mark Brown, Suzuki Poulouse, Wolfram Sang
On Sat, 25 Oct 2025, Markus Elfring wrote:
> …
> > 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.
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-06 14:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-25 14:23 [PATCH] drivers: Fix reference leak in altr_sysmgr_regmap_lookup_by_phandle() Ma Ke
2025-10-25 20:13 ` Markus Elfring
2025-11-06 14:39 ` Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).