Skip to contentSkip to conversation

soc: samsung: exynos-pmu: fix of_node refcount leak in exynos_get_pmu_regmap()

PATCH Applied Weigang He 2 participants 2 messages Jun 9 – Jun 29 Arm Samsung Exynos

lore
Share & tools
lore

Weigang He

author
#0 lore raw

PATCH v3 1/1 soc: samsung: exynos-pmu: fix of_node refcount leak in exynos_get_pmu_regmap()

exynos_get_pmu_regmap() obtains a device_node via of_find_matching_node() and passes it to exynos_get_pmu_regmap_by_phandle(np, NULL). With propname == NULL the callee uses np directly and does not drop a reference, so the reference taken by of_find_matching_node() is leaked on every call -- including on each -EPROBE_DEFER retry of the only in-tree caller, exynos_retention_init() in the Exynos pinctrl driver.

Annotate np with the __free(device_node) cleanup attribute so the reference is released when the function returns.

Found by static analysis tool CodeQL.

Fixes 76640b84bd7a ("soc: samsung: pmu: Provide global function to get PMU regmap")

---
Changes in v3:
- Only annotate the np declaration with __free(device_node); leave the rest of the function body unchanged (Krzysztof Kozlowski).

Changes in v2:
- Use the __free(device_node) cleanup attribute instead of an explicit of_node_put() and the helper refactor (Krzysztof Kozlowski); dropped the former patch 2/2.

v2: https://lore.kernel.org/linux-samsung-soc/[email protected]/
v1: https://lore.kernel.org/linux-samsung-soc/[email protected]>/

 drivers/soc/samsung/exynos-pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/samsung/exynos-pmu.c +2 -2
index d58376c38179b..f5fcdde9750e2 100644
@@ -167,8 +167,8 @@ static const struct mfd_cell exynos_pmu_devs[] = {
  */
 struct regmap *exynos_get_pmu_regmap(void)
 {
-	struct device_node *np = of_find_matching_node(NULL,
-						      exynos_pmu_of_device_ids);
+	struct device_node *np __free(device_node) =
+		of_find_matching_node(NULL, exynos_pmu_of_device_ids);
 	if (np)
 		return exynos_get_pmu_regmap_by_phandle(np, NULL);
 	return ERR_PTR(-ENODEV);

base-commit: 0f61b1860cc3f52aef9036d7235ed1f017632193

Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 8 lines · Weigang He

exynos_get_pmu_regmap() obtains a device_node via of_find_matching_node() and passes it to exynos_get_pmu_regmap_by_phandle(np, NULL). With propname == NULL the callee uses np directly and does not drop a reference, so the reference taken by of_find_matching_node() is leaked on every call -- including on each -EPROBE_DEFER retry of the only in-tree caller, exynos_retention_init() in the Exynos pinctrl driver.

[...]

Applied, thanks!

[1/1] soc: samsung: exynos-pmu: fix of_node refcount leak in exynos_get_pmu_regmap()

      https://git.kernel.org/krzk/linux/c/fa476d53edd24e8105faace04e881b9c4179738f

Best regards,

Signature · 1 line
Krzysztof Kozlowski <[email protected]>