kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths
@ 2021-04-23  7:02 Christophe JAILLET
  2021-08-29  5:27 ` Stephen Boyd
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christophe JAILLET @ 2021-04-23  7:02 UTC (permalink / raw)
  To: mturquette, sboyd, lee.jones, Julia.Lawall, gregory.clement
  Cc: linux-clk, linux-kernel, kernel-janitors, Christophe JAILLET

If we exit the for_each_of_cpu_node loop early, the reference on the
current node must be decremented, otherwise there is a leak.

Fixes: f756e362d938 ("clk: mvebu: add CPU clock driver for Armada 7K/8K")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Also, I wonder if the drivers in drivers/clk/mvebu are used by anyone.
In order to compile-test the changes, I also had to change the 'bool' in Kconfig
by 'bool "blah"'. Without this change, it was not possible to set
CONFIG_ARMADA_AP_CPU_CLK required by Makefile.

I don't know if I did something wrong, if it is an issue only on my environment
or if something got broken at some time in the build chain but it looks
spurious.

If I'm right and that these drivers never compile and no-one noticed it,
maybe removing them is better than fixing some unlikely issues and style.
If these drivers should stay, Kconfig may need some love from someone.
---
 drivers/clk/mvebu/ap-cpu-clk.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/mvebu/ap-cpu-clk.c b/drivers/clk/mvebu/ap-cpu-clk.c
index 08ba59ec3fb1..71bdd7c3ff03 100644
--- a/drivers/clk/mvebu/ap-cpu-clk.c
+++ b/drivers/clk/mvebu/ap-cpu-clk.c
@@ -256,12 +256,15 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
 		int cpu, err;
 
 		err = of_property_read_u32(dn, "reg", &cpu);
-		if (WARN_ON(err))
+		if (WARN_ON(err)) {
+			of_node_put(dn);
 			return err;
+		}
 
 		/* If cpu2 or cpu3 is enabled */
 		if (cpu & APN806_CLUSTER_NUM_MASK) {
 			nclusters = 2;
+			of_node_put(dn);
 			break;
 		}
 	}
@@ -288,8 +291,10 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
 		int cpu, err;
 
 		err = of_property_read_u32(dn, "reg", &cpu);
-		if (WARN_ON(err))
+		if (WARN_ON(err)) {
+			of_node_put(dn);
 			return err;
+		}
 
 		cluster_index = cpu & APN806_CLUSTER_NUM_MASK;
 		cluster_index >>= APN806_CLUSTER_NUM_OFFSET;
@@ -301,6 +306,7 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
 		parent = of_clk_get(np, cluster_index);
 		if (IS_ERR(parent)) {
 			dev_err(dev, "Could not get the clock parent\n");
+			of_node_put(dn);
 			return -EINVAL;
 		}
 		parent_name =  __clk_get_name(parent);
@@ -319,8 +325,10 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
 		init.parent_names = &parent_name;
 
 		ret = devm_clk_hw_register(dev, &ap_cpu_clk[cluster_index].hw);
-		if (ret)
+		if (ret) {
+			of_node_put(dn);
 			return ret;
+		}
 		ap_cpu_data->hws[cluster_index] = &ap_cpu_clk[cluster_index].hw;
 	}
 
-- 
2.27.0


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

* Re: [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths
  2021-04-23  7:02 [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths Christophe JAILLET
@ 2021-08-29  5:27 ` Stephen Boyd
  2021-08-30 11:59   ` Dan Carpenter
  2021-09-01  9:57 ` Dan Carpenter
  2021-09-15  1:25 ` Stephen Boyd
  2 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2021-08-29  5:27 UTC (permalink / raw)
  To: Christophe JAILLET, Julia.Lawall, gregory.clement, lee.jones, mturquette
  Cc: linux-clk, linux-kernel, kernel-janitors, Christophe JAILLET

Quoting Christophe JAILLET (2021-04-23 00:02:26)
> If we exit the for_each_of_cpu_node loop early, the reference on the
> current node must be decremented, otherwise there is a leak.
> 
> Fixes: f756e362d938 ("clk: mvebu: add CPU clock driver for Armada 7K/8K")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Also, I wonder if the drivers in drivers/clk/mvebu are used by anyone.
> In order to compile-test the changes, I also had to change the 'bool' in Kconfig
> by 'bool "blah"'. Without this change, it was not possible to set
> CONFIG_ARMADA_AP_CPU_CLK required by Makefile.
> 
> I don't know if I did something wrong, if it is an issue only on my environment
> or if something got broken at some time in the build chain but it looks
> spurious.
> 
> If I'm right and that these drivers never compile and no-one noticed it,
> maybe removing them is better than fixing some unlikely issues and style.
> If these drivers should stay, Kconfig may need some love from someone.

Nobody has said anything on this patch. So I'm not really sure what's
going on. Probably we never take the error path, or the whole system
fails to boot?

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

* Re: [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths
  2021-08-29  5:27 ` Stephen Boyd
@ 2021-08-30 11:59   ` Dan Carpenter
  2021-09-01  5:29     ` Stephen Boyd
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2021-08-30 11:59 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Christophe JAILLET, Julia.Lawall, gregory.clement, lee.jones,
	mturquette, linux-clk, linux-kernel, kernel-janitors

On Sat, Aug 28, 2021 at 10:27:17PM -0700, Stephen Boyd wrote:
> Quoting Christophe JAILLET (2021-04-23 00:02:26)
> > If we exit the for_each_of_cpu_node loop early, the reference on the
> > current node must be decremented, otherwise there is a leak.
> > 
> > Fixes: f756e362d938 ("clk: mvebu: add CPU clock driver for Armada 7K/8K")
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> > Also, I wonder if the drivers in drivers/clk/mvebu are used by anyone.
> > In order to compile-test the changes, I also had to change the 'bool' in Kconfig
> > by 'bool "blah"'. Without this change, it was not possible to set
> > CONFIG_ARMADA_AP_CPU_CLK required by Makefile.
> > 
> > I don't know if I did something wrong, if it is an issue only on my environment
> > or if something got broken at some time in the build chain but it looks
> > spurious.
> > 
> > If I'm right and that these drivers never compile and no-one noticed it,
> > maybe removing them is better than fixing some unlikely issues and style.
> > If these drivers should stay, Kconfig may need some love from someone.
> 
> Nobody has said anything on this patch. So I'm not really sure what's
> going on. Probably we never take the error path, or the whole system
> fails to boot?

You probably take this one.

   106                  /* If cpu2 or cpu3 is enabled */
   107                  if (cpu & APN806_CLUSTER_NUM_MASK) {
   108                          nclusters = 2;
   109  +                       of_node_put(dn);
   110                          break;
   111                  }

But, yeah, probably on one carse of "dn" can't be freed in real life.

Still probably worth fixing though just for correctness.  Otherwise it
makes static analysis less effective if people deliberately leave bugs
in the code.

regards,
dan carpenter

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

* Re: [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths
  2021-08-30 11:59   ` Dan Carpenter
@ 2021-09-01  5:29     ` Stephen Boyd
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2021-09-01  5:29 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Christophe JAILLET, Julia.Lawall, gregory.clement, lee.jones,
	mturquette, linux-clk, linux-kernel, kernel-janitors

Quoting Dan Carpenter (2021-08-30 04:59:31)
> On Sat, Aug 28, 2021 at 10:27:17PM -0700, Stephen Boyd wrote:
> > Quoting Christophe JAILLET (2021-04-23 00:02:26)
> > > If we exit the for_each_of_cpu_node loop early, the reference on the
> > > current node must be decremented, otherwise there is a leak.
> > > 
> > > Fixes: f756e362d938 ("clk: mvebu: add CPU clock driver for Armada 7K/8K")
> > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > > ---
> > > Also, I wonder if the drivers in drivers/clk/mvebu are used by anyone.
> > > In order to compile-test the changes, I also had to change the 'bool' in Kconfig
> > > by 'bool "blah"'. Without this change, it was not possible to set
> > > CONFIG_ARMADA_AP_CPU_CLK required by Makefile.
> > > 
> > > I don't know if I did something wrong, if it is an issue only on my environment
> > > or if something got broken at some time in the build chain but it looks
> > > spurious.
> > > 
> > > If I'm right and that these drivers never compile and no-one noticed it,
> > > maybe removing them is better than fixing some unlikely issues and style.
> > > If these drivers should stay, Kconfig may need some love from someone.
> > 
> > Nobody has said anything on this patch. So I'm not really sure what's
> > going on. Probably we never take the error path, or the whole system
> > fails to boot?
> 
> You probably take this one.
> 
>    106                  /* If cpu2 or cpu3 is enabled */
>    107                  if (cpu & APN806_CLUSTER_NUM_MASK) {
>    108                          nclusters = 2;
>    109  +                       of_node_put(dn);
>    110                          break;
>    111                  }
> 
> But, yeah, probably on one carse of "dn" can't be freed in real life.
> 
> Still probably worth fixing though just for correctness.  Otherwise it
> makes static analysis less effective if people deliberately leave bugs
> in the code.

Thanks. Can we turn that into a Reviewed-by?

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

* Re: [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths
  2021-04-23  7:02 [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths Christophe JAILLET
  2021-08-29  5:27 ` Stephen Boyd
@ 2021-09-01  9:57 ` Dan Carpenter
  2021-09-15  1:25 ` Stephen Boyd
  2 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2021-09-01  9:57 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: mturquette, sboyd, lee.jones, Julia.Lawall, gregory.clement,
	linux-clk, linux-kernel, kernel-janitors

On Fri, Apr 23, 2021 at 09:02:26AM +0200, Christophe JAILLET wrote:
> If we exit the for_each_of_cpu_node loop early, the reference on the
> current node must be decremented, otherwise there is a leak.
> 
> Fixes: f756e362d938 ("clk: mvebu: add CPU clock driver for Armada 7K/8K")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter


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

* Re: [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths
  2021-04-23  7:02 [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths Christophe JAILLET
  2021-08-29  5:27 ` Stephen Boyd
  2021-09-01  9:57 ` Dan Carpenter
@ 2021-09-15  1:25 ` Stephen Boyd
  2 siblings, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2021-09-15  1:25 UTC (permalink / raw)
  To: Christophe JAILLET, Julia.Lawall, gregory.clement, lee.jones, mturquette
  Cc: linux-clk, linux-kernel, kernel-janitors, Christophe JAILLET

Quoting Christophe JAILLET (2021-04-23 00:02:26)
> If we exit the for_each_of_cpu_node loop early, the reference on the
> current node must be decremented, otherwise there is a leak.
> 
> Fixes: f756e362d938 ("clk: mvebu: add CPU clock driver for Armada 7K/8K")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---

Applied to clk-next

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

end of thread, other threads:[~2021-09-15  1:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23  7:02 [PATCH] clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths Christophe JAILLET
2021-08-29  5:27 ` Stephen Boyd
2021-08-30 11:59   ` Dan Carpenter
2021-09-01  5:29     ` Stephen Boyd
2021-09-01  9:57 ` Dan Carpenter
2021-09-15  1:25 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).