[v2] clk: add missing of_node_put() in "assigned-clocks" property parsing

Message ID 20230131083227.10990-1-clement.leger@bootlin.com
State New
Headers
Series [v2] clk: add missing of_node_put() in "assigned-clocks" property parsing |

Commit Message

Clément Léger Jan. 31, 2023, 8:32 a.m. UTC
  When returning from of_parse_phandle_with_args(), the np member of the
of_phandle_args structure should be put after usage. Add missing
of_node_put() calls in both __set_clk_parents() and __set_clk_rates().

Fixes: 86be408bfbd8 ("clk: Support for clock parents and rates assigned from device tree")
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
v2:
 - Add "Fixes"

 drivers/clk/clk-conf.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
  

Comments

Clément Léger Feb. 20, 2023, 11:44 a.m. UTC | #1
Le Tue, 31 Jan 2023 09:32:27 +0100,
Clément Léger <clement.leger@bootlin.com> a écrit :

Ping ?

> When returning from of_parse_phandle_with_args(), the np member of the
> of_phandle_args structure should be put after usage. Add missing
> of_node_put() calls in both __set_clk_parents() and __set_clk_rates().
> 
> Fixes: 86be408bfbd8 ("clk: Support for clock parents and rates assigned from device tree")
> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> ---
> v2:
>  - Add "Fixes"
> 
>  drivers/clk/clk-conf.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c
> index 2ef819606c41..1a4e6340f95c 100644
> --- a/drivers/clk/clk-conf.c
> +++ b/drivers/clk/clk-conf.c
> @@ -33,9 +33,12 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier)
>  			else
>  				return rc;
>  		}
> -		if (clkspec.np == node && !clk_supplier)
> +		if (clkspec.np == node && !clk_supplier) {
> +			of_node_put(clkspec.np);
>  			return 0;
> +		}
>  		pclk = of_clk_get_from_provider(&clkspec);
> +		of_node_put(clkspec.np);
>  		if (IS_ERR(pclk)) {
>  			if (PTR_ERR(pclk) != -EPROBE_DEFER)
>  				pr_warn("clk: couldn't get parent clock %d for %pOF\n",
> @@ -48,10 +51,12 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier)
>  		if (rc < 0)
>  			goto err;
>  		if (clkspec.np == node && !clk_supplier) {
> +			of_node_put(clkspec.np);
>  			rc = 0;
>  			goto err;
>  		}
>  		clk = of_clk_get_from_provider(&clkspec);
> +		of_node_put(clkspec.np);
>  		if (IS_ERR(clk)) {
>  			if (PTR_ERR(clk) != -EPROBE_DEFER)
>  				pr_warn("clk: couldn't get assigned clock %d for %pOF\n",
> @@ -93,10 +98,13 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier)
>  				else
>  					return rc;
>  			}
> -			if (clkspec.np == node && !clk_supplier)
> +			if (clkspec.np == node && !clk_supplier) {
> +				of_node_put(clkspec.np);
>  				return 0;
> +			}
>  
>  			clk = of_clk_get_from_provider(&clkspec);
> +			of_node_put(clkspec.np);
>  			if (IS_ERR(clk)) {
>  				if (PTR_ERR(clk) != -EPROBE_DEFER)
>  					pr_warn("clk: couldn't get clock %d for %pOF\n",
  
Clément Léger March 14, 2023, 4:45 p.m. UTC | #2
Le Mon, 20 Feb 2023 12:44:20 +0100,
Clément Léger <clement.leger@bootlin.com> a écrit :

Gentle ping.

> Le Tue, 31 Jan 2023 09:32:27 +0100,
> Clément Léger <clement.leger@bootlin.com> a écrit :
> 
> Ping ?
> 
> > When returning from of_parse_phandle_with_args(), the np member of the
> > of_phandle_args structure should be put after usage. Add missing
> > of_node_put() calls in both __set_clk_parents() and __set_clk_rates().
> > 
> > Fixes: 86be408bfbd8 ("clk: Support for clock parents and rates assigned from device tree")
> > Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> > ---
> > v2:
> >  - Add "Fixes"
> > 
> >  drivers/clk/clk-conf.c | 12 ++++++++++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c
> > index 2ef819606c41..1a4e6340f95c 100644
> > --- a/drivers/clk/clk-conf.c
> > +++ b/drivers/clk/clk-conf.c
> > @@ -33,9 +33,12 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier)
> >  			else
> >  				return rc;
> >  		}
> > -		if (clkspec.np == node && !clk_supplier)
> > +		if (clkspec.np == node && !clk_supplier) {
> > +			of_node_put(clkspec.np);
> >  			return 0;
> > +		}
> >  		pclk = of_clk_get_from_provider(&clkspec);
> > +		of_node_put(clkspec.np);
> >  		if (IS_ERR(pclk)) {
> >  			if (PTR_ERR(pclk) != -EPROBE_DEFER)
> >  				pr_warn("clk: couldn't get parent clock %d for %pOF\n",
> > @@ -48,10 +51,12 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier)
> >  		if (rc < 0)
> >  			goto err;
> >  		if (clkspec.np == node && !clk_supplier) {
> > +			of_node_put(clkspec.np);
> >  			rc = 0;
> >  			goto err;
> >  		}
> >  		clk = of_clk_get_from_provider(&clkspec);
> > +		of_node_put(clkspec.np);
> >  		if (IS_ERR(clk)) {
> >  			if (PTR_ERR(clk) != -EPROBE_DEFER)
> >  				pr_warn("clk: couldn't get assigned clock %d for %pOF\n",
> > @@ -93,10 +98,13 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier)
> >  				else
> >  					return rc;
> >  			}
> > -			if (clkspec.np == node && !clk_supplier)
> > +			if (clkspec.np == node && !clk_supplier) {
> > +				of_node_put(clkspec.np);
> >  				return 0;
> > +			}
> >  
> >  			clk = of_clk_get_from_provider(&clkspec);
> > +			of_node_put(clkspec.np);
> >  			if (IS_ERR(clk)) {
> >  				if (PTR_ERR(clk) != -EPROBE_DEFER)
> >  					pr_warn("clk: couldn't get clock %d for %pOF\n",  
> 
> 
>
  
Stephen Boyd March 15, 2023, 12:44 a.m. UTC | #3
Quoting Clément Léger (2023-01-31 00:32:27)
> When returning from of_parse_phandle_with_args(), the np member of the
> of_phandle_args structure should be put after usage. Add missing
> of_node_put() calls in both __set_clk_parents() and __set_clk_rates().
> 
> Fixes: 86be408bfbd8 ("clk: Support for clock parents and rates assigned from device tree")
> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> ---

Does this series from a year ago help[1]?

[1] https://lore.kernel.org/all/20220623121857.886-1-nuno.sa@analog.com/

Nobody reviewed it, but if you can then I can probably apply it.
  
Clément Léger March 28, 2023, 7:46 a.m. UTC | #4
Le Tue, 14 Mar 2023 17:44:35 -0700,
Stephen Boyd <sboyd@kernel.org> a écrit :

> Quoting Clément Léger (2023-01-31 00:32:27)
> > When returning from of_parse_phandle_with_args(), the np member of the
> > of_phandle_args structure should be put after usage. Add missing
> > of_node_put() calls in both __set_clk_parents() and __set_clk_rates().
> > 
> > Fixes: 86be408bfbd8 ("clk: Support for clock parents and rates assigned from device tree")
> > Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> > ---  
> 
> Does this series from a year ago help[1]?
> 
> [1] https://lore.kernel.org/all/20220623121857.886-1-nuno.sa@analog.com/
> 
> Nobody reviewed it, but if you can then I can probably apply it.

I'm only be able to review the first patch of the serie which
is equivalent to what I did but it mixes refactoring and fixes.
  
Stephen Boyd March 29, 2023, 8:55 p.m. UTC | #5
Quoting Clément Léger (2023-01-31 00:32:27)
> When returning from of_parse_phandle_with_args(), the np member of the
> of_phandle_args structure should be put after usage. Add missing
> of_node_put() calls in both __set_clk_parents() and __set_clk_rates().
> 
> Fixes: 86be408bfbd8 ("clk: Support for clock parents and rates assigned from device tree")
> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> ---

Applied to clk-next
  

Patch

diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c
index 2ef819606c41..1a4e6340f95c 100644
--- a/drivers/clk/clk-conf.c
+++ b/drivers/clk/clk-conf.c
@@ -33,9 +33,12 @@  static int __set_clk_parents(struct device_node *node, bool clk_supplier)
 			else
 				return rc;
 		}
-		if (clkspec.np == node && !clk_supplier)
+		if (clkspec.np == node && !clk_supplier) {
+			of_node_put(clkspec.np);
 			return 0;
+		}
 		pclk = of_clk_get_from_provider(&clkspec);
+		of_node_put(clkspec.np);
 		if (IS_ERR(pclk)) {
 			if (PTR_ERR(pclk) != -EPROBE_DEFER)
 				pr_warn("clk: couldn't get parent clock %d for %pOF\n",
@@ -48,10 +51,12 @@  static int __set_clk_parents(struct device_node *node, bool clk_supplier)
 		if (rc < 0)
 			goto err;
 		if (clkspec.np == node && !clk_supplier) {
+			of_node_put(clkspec.np);
 			rc = 0;
 			goto err;
 		}
 		clk = of_clk_get_from_provider(&clkspec);
+		of_node_put(clkspec.np);
 		if (IS_ERR(clk)) {
 			if (PTR_ERR(clk) != -EPROBE_DEFER)
 				pr_warn("clk: couldn't get assigned clock %d for %pOF\n",
@@ -93,10 +98,13 @@  static int __set_clk_rates(struct device_node *node, bool clk_supplier)
 				else
 					return rc;
 			}
-			if (clkspec.np == node && !clk_supplier)
+			if (clkspec.np == node && !clk_supplier) {
+				of_node_put(clkspec.np);
 				return 0;
+			}
 
 			clk = of_clk_get_from_provider(&clkspec);
+			of_node_put(clkspec.np);
 			if (IS_ERR(clk)) {
 				if (PTR_ERR(clk) != -EPROBE_DEFER)
 					pr_warn("clk: couldn't get clock %d for %pOF\n",