[PATCH] soc: samsung: exynos-pmu: fix reference count leak in exynos_get_pmu_regmap_by_phandle

Miaoqian Lin posted 1 patch 3 months, 1 week ago
drivers/soc/samsung/exynos-pmu.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] soc: samsung: exynos-pmu: fix reference count leak in exynos_get_pmu_regmap_by_phandle
Posted by Miaoqian Lin 3 months, 1 week ago
The driver_find_device_by_of_node() function calls driver_find_device
and returns a device with its reference count incremented.
Add the missing put_device() call to
release this reference after the device is used.

Found via static analysis.

Fixes: 0b7c6075022c ("soc: samsung: exynos-pmu: Add regmap support for SoCs that protect PMU regs")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/soc/samsung/exynos-pmu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/soc/samsung/exynos-pmu.c b/drivers/soc/samsung/exynos-pmu.c
index 22c50ca2aa79..a53c1f882e1a 100644
--- a/drivers/soc/samsung/exynos-pmu.c
+++ b/drivers/soc/samsung/exynos-pmu.c
@@ -346,6 +346,7 @@ struct regmap *exynos_get_pmu_regmap_by_phandle(struct device_node *np,
 	if (!dev)
 		return ERR_PTR(-EPROBE_DEFER);
 
+	put_device(dev);
 	return syscon_node_to_regmap(pmu_np);
 }
 EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap_by_phandle);
-- 
2.39.5 (Apple Git-154)
Re: [PATCH] soc: samsung: exynos-pmu: fix reference count leak in exynos_get_pmu_regmap_by_phandle
Posted by Krzysztof Kozlowski 3 months, 1 week ago
On 28/10/2025 04:15, Miaoqian Lin wrote:
> The driver_find_device_by_of_node() function calls driver_find_device
> and returns a device with its reference count incremented.
> Add the missing put_device() call to
> release this reference after the device is used.
> 
> Found via static analysis.

What static analysis? You must name the tool.

Anyway, same comments as before.

https://lore.kernel.org/all/?q=dfn%3Adrivers%2Fsoc%2Fsamsung%2Fexynos-pmu.c

Best regards,
Krzysztof
Re: [PATCH] soc: samsung: exynos-pmu: fix reference count leak in exynos_get_pmu_regmap_by_phandle
Posted by 林妙倩 3 months, 1 week ago
Hi, Krzysztof

Thanks for your review.

Krzysztof Kozlowski <krzk@kernel.org> 于2025年10月28日周二 16:42写道:
>
> On 28/10/2025 04:15, Miaoqian Lin wrote:
> > The driver_find_device_by_of_node() function calls driver_find_device
> > and returns a device with its reference count incremented.
> > Add the missing put_device() call to
> > release this reference after the device is used.
> >
> > Found via static analysis.
>
> What static analysis? You must name the tool.
>

I use weggli (AST pattern search) followed by manual review.

> Anyway, same comments as before.
>
> https://lore.kernel.org/all/?q=dfn%3Adrivers%2Fsoc%2Fsamsung%2Fexynos-pmu.c

Got it, thanks.


>
> Best regards,
> Krzysztof