mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pmdomain: renesas: rcar-sysc: Fix CPG/MSTP node reference leak
@ 2026-11-24 15:38 Yuho Choi
  2026-11-26 13:32 ` Ulf Hansson
  2026-11-26 13:36 ` Geert Uytterhoeven
  0 siblings, 2 replies; 3+ messages in thread
From: Yuho Choi @ 2026-11-24 15:38 UTC (permalink / raw)
  To: Geert Uytterhoeven, Ulf Hansson
  Cc: Magnus Damm, linux-renesas-soc, linux-pm, linux-kernel, Yuho Choi

rcar_sysc_pd_init() checks whether the device tree has a
"renesas,cpg-mstp-clocks" node by storing the result of
of_find_compatible_node() in the bool has_cpg_mstp. The returned node
has its reference count raised, and the reference is lost when the
pointer is converted to a bool. rcar_sysc_pd_init() runs once as an
early initcall, so this leaks a single reference at boot.

Keep the node in a local variable and put it after the check.

Fixes: 1c8c77f52d10 ("soc: renesas: rcar-sysc: Enable Clock Domain for I/O devices")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
Compile-tested only (ARM multi_v7_defconfig, W=1). I have no R-Car
board to test it on.

 drivers/pmdomain/renesas/rcar-sysc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/pmdomain/renesas/rcar-sysc.c b/drivers/pmdomain/renesas/rcar-sysc.c
index 3c8a44c6d772..20acc9dece6b 100644
--- a/drivers/pmdomain/renesas/rcar-sysc.c
+++ b/drivers/pmdomain/renesas/rcar-sysc.c
@@ -353,7 +353,7 @@ static int __init rcar_sysc_pd_init(void)
 	const struct rcar_sysc_info *info;
 	const struct of_device_id *match;
 	struct rcar_pm_domains *domains;
-	struct device_node *np;
+	struct device_node *np, *cpg_np;
 	void __iomem *base;
 	unsigned int i;
 	int error;
@@ -370,8 +370,9 @@ static int __init rcar_sysc_pd_init(void)
 			goto out_put;
 	}
 
-	has_cpg_mstp = of_find_compatible_node(NULL, NULL,
-					       "renesas,cpg-mstp-clocks");
+	cpg_np = of_find_compatible_node(NULL, NULL, "renesas,cpg-mstp-clocks");
+	has_cpg_mstp = cpg_np;
+	of_node_put(cpg_np);
 
 	base = of_iomap(np, 0);
 	if (!base) {

base-commit: 8dac6df92a2e66e2098bbc69061964cfe7e8375b
-- 
2.56.1


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

* Re: [PATCH] pmdomain: renesas: rcar-sysc: Fix CPG/MSTP node reference leak
  2026-11-24 15:38 [PATCH] pmdomain: renesas: rcar-sysc: Fix CPG/MSTP node reference leak Yuho Choi
@ 2026-11-26 13:32 ` Ulf Hansson
  2026-11-26 13:36 ` Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2026-11-26 13:32 UTC (permalink / raw)
  To: Yuho Choi
  Cc: Geert Uytterhoeven, Ulf Hansson, Magnus Damm, linux-renesas-soc,
	linux-pm, linux-kernel

On Tue, Nov 24, 2026 at 4:38 PM Yuho Choi <oss.patchbox@gmail.com> wrote:
>
> rcar_sysc_pd_init() checks whether the device tree has a
> "renesas,cpg-mstp-clocks" node by storing the result of
> of_find_compatible_node() in the bool has_cpg_mstp. The returned node
> has its reference count raised, and the reference is lost when the
> pointer is converted to a bool. rcar_sysc_pd_init() runs once as an
> early initcall, so this leaks a single reference at boot.
>
> Keep the node in a local variable and put it after the check.
>
> Fixes: 1c8c77f52d10 ("soc: renesas: rcar-sysc: Enable Clock Domain for I/O devices")
> Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>

Applied for fixes and by adding a stable tag, thanks!

Kind regards
Uffe


> ---
> Compile-tested only (ARM multi_v7_defconfig, W=1). I have no R-Car
> board to test it on.
>
>  drivers/pmdomain/renesas/rcar-sysc.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pmdomain/renesas/rcar-sysc.c b/drivers/pmdomain/renesas/rcar-sysc.c
> index 3c8a44c6d772..20acc9dece6b 100644
> --- a/drivers/pmdomain/renesas/rcar-sysc.c
> +++ b/drivers/pmdomain/renesas/rcar-sysc.c
> @@ -353,7 +353,7 @@ static int __init rcar_sysc_pd_init(void)
>         const struct rcar_sysc_info *info;
>         const struct of_device_id *match;
>         struct rcar_pm_domains *domains;
> -       struct device_node *np;
> +       struct device_node *np, *cpg_np;
>         void __iomem *base;
>         unsigned int i;
>         int error;
> @@ -370,8 +370,9 @@ static int __init rcar_sysc_pd_init(void)
>                         goto out_put;
>         }
>
> -       has_cpg_mstp = of_find_compatible_node(NULL, NULL,
> -                                              "renesas,cpg-mstp-clocks");
> +       cpg_np = of_find_compatible_node(NULL, NULL, "renesas,cpg-mstp-clocks");
> +       has_cpg_mstp = cpg_np;
> +       of_node_put(cpg_np);
>
>         base = of_iomap(np, 0);
>         if (!base) {
>
> base-commit: 8dac6df92a2e66e2098bbc69061964cfe7e8375b
> --
> 2.56.1
>

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

* Re: [PATCH] pmdomain: renesas: rcar-sysc: Fix CPG/MSTP node reference leak
  2026-11-24 15:38 [PATCH] pmdomain: renesas: rcar-sysc: Fix CPG/MSTP node reference leak Yuho Choi
  2026-11-26 13:32 ` Ulf Hansson
@ 2026-11-26 13:36 ` Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2026-11-26 13:36 UTC (permalink / raw)
  To: Yuho Choi, Ulf Hansson
  Cc: Magnus Damm, linux-renesas-soc, linux-pm, linux-kernel

On Tue, Nov 24, 2026, at 16:38, Yuho Choi wrote:
> rcar_sysc_pd_init() checks whether the device tree has a
> "renesas,cpg-mstp-clocks" node by storing the result of
> of_find_compatible_node() in the bool has_cpg_mstp. The returned node
> has its reference count raised, and the reference is lost when the
> pointer is converted to a bool. rcar_sysc_pd_init() runs once as an
> early initcall, so this leaks a single reference at boot.
>
> Keep the node in a local variable and put it after the check.
>
> Fixes: 1c8c77f52d10 ("soc: renesas: rcar-sysc: Enable Clock Domain for 
> I/O devices")
> Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                                                Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                                            -- Linus Torvalds

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 15:38 [PATCH] pmdomain: renesas: rcar-sysc: Fix CPG/MSTP node reference leak Yuho Choi
2026-11-26 13:32 ` Ulf Hansson
2026-11-26 13:36 ` Geert Uytterhoeven

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®