linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: Make clk_bulk_get_all() return a valid "id"
@ 2019-09-13  2:40 Bjorn Andersson
  2019-09-13 14:44 ` Jordan Crouse
  2019-09-17 20:33 ` Stephen Boyd
  0 siblings, 2 replies; 4+ messages in thread
From: Bjorn Andersson @ 2019-09-13  2:40 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: linux-clk, linux-kernel, linux-arm-msm, Dong Aisheng, Jordan Crouse

The adreno driver expects the "id" field of the returned clk_bulk_data
to be filled in with strings from the clock-names property.

But due to the use of kmalloc_array() in of_clk_bulk_get_all() it
receives a list of bogus pointers instead.

Zero-initialize the "id" field and attempt to populate with strings from
the clock-names property to resolve both these issues.

Fixes: 616e45df7c4a ("clk: add new APIs to operate on all available clocks")
Fixes: 8e3e791d20d2 ("drm/msm: Use generic bulk clock function")
Cc: Dong Aisheng <aisheng.dong@nxp.com>
Cc: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
 drivers/clk/clk-bulk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-bulk.c b/drivers/clk/clk-bulk.c
index 524bf9a53098..e9e16425c739 100644
--- a/drivers/clk/clk-bulk.c
+++ b/drivers/clk/clk-bulk.c
@@ -18,10 +18,13 @@ static int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,
 	int ret;
 	int i;
 
-	for (i = 0; i < num_clks; i++)
+	for (i = 0; i < num_clks; i++) {
+		clks[i].id = NULL;
 		clks[i].clk = NULL;
+	}
 
 	for (i = 0; i < num_clks; i++) {
+		of_property_read_string_index(np, "clock-names", i, &clks[i].id);
 		clks[i].clk = of_clk_get(np, i);
 		if (IS_ERR(clks[i].clk)) {
 			ret = PTR_ERR(clks[i].clk);
-- 
2.18.0


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

* Re: [PATCH] clk: Make clk_bulk_get_all() return a valid "id"
  2019-09-13  2:40 [PATCH] clk: Make clk_bulk_get_all() return a valid "id" Bjorn Andersson
@ 2019-09-13 14:44 ` Jordan Crouse
  2019-09-17 20:33 ` Stephen Boyd
  1 sibling, 0 replies; 4+ messages in thread
From: Jordan Crouse @ 2019-09-13 14:44 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Michael Turquette, Stephen Boyd, linux-clk, linux-kernel,
	linux-arm-msm, Dong Aisheng

On Thu, Sep 12, 2019 at 07:40:29PM -0700, Bjorn Andersson wrote:
> The adreno driver expects the "id" field of the returned clk_bulk_data
> to be filled in with strings from the clock-names property.
> 
> But due to the use of kmalloc_array() in of_clk_bulk_get_all() it
> receives a list of bogus pointers instead.
> 
> Zero-initialize the "id" field and attempt to populate with strings from
> the clock-names property to resolve both these issues.

This looks great to me.  Thanks for fixing that so quickly.

Reviewed-by: Jordan Crouse <jcrouse@codeaurora.org>

> Fixes: 616e45df7c4a ("clk: add new APIs to operate on all available clocks")
> Fixes: 8e3e791d20d2 ("drm/msm: Use generic bulk clock function")
> Cc: Dong Aisheng <aisheng.dong@nxp.com>
> Cc: Jordan Crouse <jcrouse@codeaurora.org>
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
>  drivers/clk/clk-bulk.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk-bulk.c b/drivers/clk/clk-bulk.c
> index 524bf9a53098..e9e16425c739 100644
> --- a/drivers/clk/clk-bulk.c
> +++ b/drivers/clk/clk-bulk.c
> @@ -18,10 +18,13 @@ static int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,
>  	int ret;
>  	int i;
>  
> -	for (i = 0; i < num_clks; i++)
> +	for (i = 0; i < num_clks; i++) {
> +		clks[i].id = NULL;
>  		clks[i].clk = NULL;
> +	}
>  
>  	for (i = 0; i < num_clks; i++) {
> +		of_property_read_string_index(np, "clock-names", i, &clks[i].id);
>  		clks[i].clk = of_clk_get(np, i);
>  		if (IS_ERR(clks[i].clk)) {
>  			ret = PTR_ERR(clks[i].clk);
> -- 
> 2.18.0
> 

-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH] clk: Make clk_bulk_get_all() return a valid "id"
  2019-09-13  2:40 [PATCH] clk: Make clk_bulk_get_all() return a valid "id" Bjorn Andersson
  2019-09-13 14:44 ` Jordan Crouse
@ 2019-09-17 20:33 ` Stephen Boyd
  2019-09-17 20:42   ` Bjorn Andersson
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2019-09-17 20:33 UTC (permalink / raw)
  To: Bjorn Andersson, Michael Turquette
  Cc: linux-clk, linux-kernel, linux-arm-msm, Dong Aisheng, Jordan Crouse

Quoting Bjorn Andersson (2019-09-12 19:40:29)
> The adreno driver expects the "id" field of the returned clk_bulk_data
> to be filled in with strings from the clock-names property.
> 
> But due to the use of kmalloc_array() in of_clk_bulk_get_all() it
> receives a list of bogus pointers instead.
> 
> Zero-initialize the "id" field and attempt to populate with strings from
> the clock-names property to resolve both these issues.
> 
> Fixes: 616e45df7c4a ("clk: add new APIs to operate on all available clocks")
> Fixes: 8e3e791d20d2 ("drm/msm: Use generic bulk clock function")
> Cc: Dong Aisheng <aisheng.dong@nxp.com>
> Cc: Jordan Crouse <jcrouse@codeaurora.org>
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---

Applied to clk-next

And now I see that this whole thing needs to be inlined to the one call
site and should use the struct device instead of calling of_clk_get()...
I'll have to fix it later.


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

* Re: [PATCH] clk: Make clk_bulk_get_all() return a valid "id"
  2019-09-17 20:33 ` Stephen Boyd
@ 2019-09-17 20:42   ` Bjorn Andersson
  0 siblings, 0 replies; 4+ messages in thread
From: Bjorn Andersson @ 2019-09-17 20:42 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Michael Turquette, linux-clk, linux-kernel, linux-arm-msm,
	Dong Aisheng, Jordan Crouse

On Tue 17 Sep 13:33 PDT 2019, Stephen Boyd wrote:

> Quoting Bjorn Andersson (2019-09-12 19:40:29)
> > The adreno driver expects the "id" field of the returned clk_bulk_data
> > to be filled in with strings from the clock-names property.
> > 
> > But due to the use of kmalloc_array() in of_clk_bulk_get_all() it
> > receives a list of bogus pointers instead.
> > 
> > Zero-initialize the "id" field and attempt to populate with strings from
> > the clock-names property to resolve both these issues.
> > 
> > Fixes: 616e45df7c4a ("clk: add new APIs to operate on all available clocks")
> > Fixes: 8e3e791d20d2 ("drm/msm: Use generic bulk clock function")
> > Cc: Dong Aisheng <aisheng.dong@nxp.com>
> > Cc: Jordan Crouse <jcrouse@codeaurora.org>
> > Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> > ---
> 
> Applied to clk-next
> 

Thanks

> And now I see that this whole thing needs to be inlined to the one call
> site and should use the struct device instead of calling of_clk_get()...
> I'll have to fix it later.
> 

I concluded the same, sorry for not mentioning it.

Regards,
Bjorn

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

end of thread, other threads:[~2019-09-17 20:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-13  2:40 [PATCH] clk: Make clk_bulk_get_all() return a valid "id" Bjorn Andersson
2019-09-13 14:44 ` Jordan Crouse
2019-09-17 20:33 ` Stephen Boyd
2019-09-17 20:42   ` Bjorn Andersson

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).