mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] soc: dove: fix OF node leak in dove_init_pmu()
@ 2026-11-27  7:42 zhaofeng2
  2026-11-27 14:46 ` Andrew Lunn
  2026-11-30  3:38 ` [PATCH v2] soc: dove: fix OF node leaks " zhaofeng2
  0 siblings, 2 replies; 4+ messages in thread
From: zhaofeng2 @ 2026-11-27  7:42 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: Zhao Feng, linux-arm-kernel, linux-kernel

From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

dove_init_pmu() calls of_get_child_by_name() to obtain the
"domains" child node of the PMU node, but the reference is
leaked on the two early failure paths and on the successful
return.

Drop the reference with of_node_put() once the node is no
longer needed.

Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
---
Verified against current tree. Leak found by code inspection
(OF reference-counting audit of dove_init_pmu()).

 soc/dove/pmu.c | 11 +--------++---
 1 file changed, 8 insertions(+), 3 deletions(-)

--- a/drivers/soc/dove/pmu.c
+++ b/drivers/soc/dove/pmu.c
@@ -388,8 +388,10 @@
 	}
 
 	pmu = kzalloc(sizeof(*pmu), GFP_KERNEL);
-	if (!pmu)
+	if (!pmu) {
+		of_node_put(domains_node);
 		return -ENOMEM;
+	}
 
 	spin_lock_init(&pmu->lock);
 	pmu->of_node = np_pmu;
@@ -400,6 +402,7 @@
 		iounmap(pmu->pmu_base);
 		iounmap(pmu->pmc_base);
 		kfree(pmu);
+		of_node_put(domains_node);
 		return -ENOMEM;
 	}
 
@@ -451,5 +454,7 @@
 			pr_err("dove_init_pmu_irq() failed: %d\n", ret);
 	}
 
-	return 0;
-}
+	of_node_put(domains_node);
+
+	return 0;
+}



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] soc: dove: fix OF node leak in dove_init_pmu()
  2026-11-27  7:42 [PATCH] soc: dove: fix OF node leak in dove_init_pmu() zhaofeng2
@ 2026-11-27 14:46 ` Andrew Lunn
  2026-11-30  3:38 ` [PATCH v2] soc: dove: fix OF node leaks " zhaofeng2
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2026-11-27 14:46 UTC (permalink / raw)
  To: zhaofeng2; +Cc: linux-arm-kernel, linux-kernel

> @@ -451,5 +454,7 @@
>  			pr_err("dove_init_pmu_irq() failed: %d\n", ret);
>  	}
>  
> -	return 0;
> -}
> +	of_node_put(domains_node);
> +
> +	return 0;
> +}

The logic of the change looks O.K. But this hunk looks odd. I would
expect it to be:

+
+	of_node_put(domains_node);
+
 	return 0;
 }

i.e. insert the put. Why did it replace the return 0;. Is there a
space/tab issue here?

	  Andrew

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] soc: dove: fix OF node leaks in dove_init_pmu()
  2026-11-27  7:42 [PATCH] soc: dove: fix OF node leak in dove_init_pmu() zhaofeng2
  2026-11-27 14:46 ` Andrew Lunn
@ 2026-11-30  3:38 ` zhaofeng2
  2026-11-30 13:01   ` Andrew Lunn
  1 sibling, 1 reply; 4+ messages in thread
From: zhaofeng2 @ 2026-11-30  3:38 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: Zhao Feng, linux-arm-kernel, linux-kernel

From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

dove_init_pmu() takes two OF node references: np_pmu via
of_find_compatible_node() and domains_node via of_get_child_by_name().
On success np_pmu is transferred to the long-lived pmu_data
(pmu->of_node), but several paths leak references:

- missing domains node: np_pmu is leaked;
- pmu allocation failure: np_pmu and domains_node are leaked;
- of_iomap() failure: both are leaked (pmu is freed, dropping the
  only holder of the np_pmu reference);
- success: domains_node is never released after the child-node
  loop.

Drop the references on all these paths.  The np_pmu reference on the
success path stays with pmu->of_node, which lives for the lifetime
of the system.

Fixes: 44e259ac909f ("ARM: dove: create a proper PMU driver for power domains, PMU IRQs and resets")
Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
---
v2: rework against current upstream master, which restructured the
    driver since v1 was written (kzalloc_obj(), scoped child-node
    iterator); the leaks themselves are unchanged.  Also fixes the
    odd trailing hunk Andrew noted in v1 - the of_node_put() is now
    a plain insertion before "return 0".

Verified against current upstream master.  Leak found by code
inspection (OF reference-counting audit of dove_init_pmu()).

 drivers/soc/dove/pmu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

--- a/drivers/soc/dove/pmu.c
+++ b/drivers/soc/dove/pmu.c
@@ -383,12 +383,16 @@ int __init dove_init_pmu(void)
 	domains_node = of_get_child_by_name(np_pmu, "domains");
 	if (!domains_node) {
 		pr_err("%pOFn: failed to find domains sub-node\n", np_pmu);
+		of_node_put(np_pmu);
 		return 0;
 	}
 
 	pmu = kzalloc_obj(*pmu);
-	if (!pmu)
+	if (!pmu) {
+		of_node_put(domains_node);
+		of_node_put(np_pmu);
 		return -ENOMEM;
+	}
 
 	spin_lock_init(&pmu->lock);
 	pmu->of_node = np_pmu;
@@ -399,6 +404,8 @@ int __init dove_init_pmu(void)
 		iounmap(pmu->pmu_base);
 		iounmap(pmu->pmc_base);
 		kfree(pmu);
+		of_node_put(domains_node);
+		of_node_put(np_pmu);
 		return -ENOMEM;
 	}
 
@@ -450,5 +457,7 @@ int __init dove_init_pmu(void)
 			pr_err("dove_init_pmu_irq() failed: %d\n", ret);
 	}
 
+	of_node_put(domains_node);
+
 	return 0;
 }



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] soc: dove: fix OF node leaks in dove_init_pmu()
  2026-11-30  3:38 ` [PATCH v2] soc: dove: fix OF node leaks " zhaofeng2
@ 2026-11-30 13:01   ` Andrew Lunn
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2026-11-30 13:01 UTC (permalink / raw)
  To: zhaofeng2; +Cc: linux-arm-kernel, linux-kernel

On Mon, Nov 30, 2026 at 11:38:28AM +0800, zhaofeng2 wrote:
> From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
> 
> dove_init_pmu() takes two OF node references: np_pmu via
> of_find_compatible_node() and domains_node via of_get_child_by_name().
> On success np_pmu is transferred to the long-lived pmu_data
> (pmu->of_node), but several paths leak references:
> 
> - missing domains node: np_pmu is leaked;
> - pmu allocation failure: np_pmu and domains_node are leaked;
> - of_iomap() failure: both are leaked (pmu is freed, dropping the
>   only holder of the np_pmu reference);
> - success: domains_node is never released after the child-node
>   loop.
> 
> Drop the references on all these paths.  The np_pmu reference on the
> success path stays with pmu->of_node, which lives for the lifetime
> of the system.
> 
> Fixes: 44e259ac909f ("ARM: dove: create a proper PMU driver for power domains, PMU IRQs and resets")
> Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

Who does this bother?

https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html

Please drop the fixes tag.

	Andrew

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30 13:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27  7:42 [PATCH] soc: dove: fix OF node leak in dove_init_pmu() zhaofeng2
2026-11-27 14:46 ` Andrew Lunn
2026-11-30  3:38 ` [PATCH v2] soc: dove: fix OF node leaks " zhaofeng2
2026-11-30 13:01   ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®