[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251025142352.25475-1-make24@iscas.ac.cn>
Date: Sat, 25 Oct 2025 22:23:52 +0800
From: Ma Ke <make24@...as.ac.cn>
To: lee@...nel.org,
suzuki.poulose@....com,
broonie@...nel.org,
mdf@...nel.org,
wsa@...nel.org
Cc: linux-kernel@...r.kernel.org,
akpm@...ux-foundation.org,
Ma Ke <make24@...as.ac.cn>,
stable@...r.kernel.org
Subject: [PATCH] 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.
Cc: stable@...r.kernel.org
Fixes: cfba5de9b99f ("drivers: Introduce device lookup variants by of_node")
Signed-off-by: Ma Ke <make24@...as.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
Powered by blists - more mailing lists