public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk()
@ 2024-08-27  2:52 Yan Zhen
  2024-08-27 18:18 ` Stephen Boyd
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Yan Zhen @ 2024-08-27  2:52 UTC (permalink / raw)
  To: andersson, mturquette, sboyd
  Cc: linux-arm-msm, linux-clk, linux-kernel, opensource.kernel,
	Yan Zhen

The devm_clk_hw_get_clk() function returns error pointers.
It never returns NULL.  Update the check accordingly.

Fixes: 8737ec830ee3 ("clk: qcom: common: Add interconnect clocks support")'
Signed-off-by: Yan Zhen <yanzhen@vivo.com>
---

Changes in v3:
- Providing a "fixes" tag blaming the commit.

 drivers/clk/qcom/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/qcom/common.c b/drivers/clk/qcom/common.c
index 33cc1f73c69d..5a9e653916ea 100644
--- a/drivers/clk/qcom/common.c
+++ b/drivers/clk/qcom/common.c
@@ -273,8 +273,8 @@ static int qcom_cc_icc_register(struct device *dev,
 		icd[i].slave_id = desc->icc_hws[i].slave_id;
 		hws = &desc->clks[desc->icc_hws[i].clk_id]->hw;
 		icd[i].clk = devm_clk_hw_get_clk(dev, hws, "icc");
-		if (!icd[i].clk)
-			return dev_err_probe(dev, -ENOENT,
+		if (IS_ERR(icd[i].clk))
+			return dev_err_probe(dev, PTR_ERR(icd[i].clk),
 					     "(%d) clock entry is null\n", i);
 		icd[i].name = clk_hw_get_name(hws);
 	}
-- 
2.34.1


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

* Re: [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk()
  2024-08-27  2:52 [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk() Yan Zhen
@ 2024-08-27 18:18 ` Stephen Boyd
  2024-08-27 20:08   ` Markus Elfring
  2024-08-29  9:06   ` Dmitry Baryshkov
  2024-08-29  9:07 ` Dmitry Baryshkov
  2024-08-29 16:59 ` Christophe JAILLET
  2 siblings, 2 replies; 7+ messages in thread
From: Stephen Boyd @ 2024-08-27 18:18 UTC (permalink / raw)
  To: Yan Zhen, andersson, mturquette
  Cc: linux-arm-msm, linux-clk, linux-kernel, opensource.kernel,
	Yan Zhen

Quoting Yan Zhen (2024-08-26 19:52:52)
> The devm_clk_hw_get_clk() function returns error pointers.
> It never returns NULL.  Update the check accordingly.

It can return NULL if the 'hw' pointer passed in is NULL.

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

* Re: [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk()
  2024-08-27 18:18 ` Stephen Boyd
@ 2024-08-27 20:08   ` Markus Elfring
  2024-08-29  9:06   ` Dmitry Baryshkov
  1 sibling, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2024-08-27 20:08 UTC (permalink / raw)
  To: Stephen Boyd, linux-clk, linux-arm-msm, opensource.kernel,
	Bjorn Andersson, Michael Turquette, Yan Zhen
  Cc: LKML

> > The devm_clk_hw_get_clk() function returns error pointers.
> > It never returns NULL.  Update the check accordingly.
>
> It can return NULL if the 'hw' pointer passed in is NULL.

How does this view fit to a published function implementation?
https://elixir.bootlin.com/linux/v6.11-rc5/source/drivers/clk/clk.c#L4703

Regards,
Markus

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

* Re: [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk()
  2024-08-27 18:18 ` Stephen Boyd
  2024-08-27 20:08   ` Markus Elfring
@ 2024-08-29  9:06   ` Dmitry Baryshkov
  2024-08-29 17:42     ` Stephen Boyd
  1 sibling, 1 reply; 7+ messages in thread
From: Dmitry Baryshkov @ 2024-08-29  9:06 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Yan Zhen, andersson, mturquette, linux-arm-msm, linux-clk,
	linux-kernel, opensource.kernel

On Tue, Aug 27, 2024 at 11:18:10AM GMT, Stephen Boyd wrote:
> Quoting Yan Zhen (2024-08-26 19:52:52)
> > The devm_clk_hw_get_clk() function returns error pointers.
> > It never returns NULL.  Update the check accordingly.
> 
> It can return NULL if the 'hw' pointer passed in is NULL.

No, it will crash:

        WARN_ON_ONCE(dev != hw->core->dev);

Furthermore, clk_hw_get_clk() also doesn't have NULL checks and will
crash if NULL is passed as hw.

struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id)
{
        struct device *dev = hw->core->dev;


-- 
With best wishes
Dmitry

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

* Re: [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk()
  2024-08-27  2:52 [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk() Yan Zhen
  2024-08-27 18:18 ` Stephen Boyd
@ 2024-08-29  9:07 ` Dmitry Baryshkov
  2024-08-29 16:59 ` Christophe JAILLET
  2 siblings, 0 replies; 7+ messages in thread
From: Dmitry Baryshkov @ 2024-08-29  9:07 UTC (permalink / raw)
  To: Yan Zhen
  Cc: andersson, mturquette, sboyd, linux-arm-msm, linux-clk,
	linux-kernel, opensource.kernel

On Tue, Aug 27, 2024 at 10:52:52AM GMT, Yan Zhen wrote:
> The devm_clk_hw_get_clk() function returns error pointers.
> It never returns NULL.  Update the check accordingly.
> 
> Fixes: 8737ec830ee3 ("clk: qcom: common: Add interconnect clocks support")'
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> ---
> 
> Changes in v3:
> - Providing a "fixes" tag blaming the commit.
> 
>  drivers/clk/qcom/common.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

-- 
With best wishes
Dmitry

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

* Re: [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk()
  2024-08-27  2:52 [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk() Yan Zhen
  2024-08-27 18:18 ` Stephen Boyd
  2024-08-29  9:07 ` Dmitry Baryshkov
@ 2024-08-29 16:59 ` Christophe JAILLET
  2 siblings, 0 replies; 7+ messages in thread
From: Christophe JAILLET @ 2024-08-29 16:59 UTC (permalink / raw)
  To: Yan Zhen, andersson, mturquette, sboyd
  Cc: linux-arm-msm, linux-clk, linux-kernel, opensource.kernel

Le 27/08/2024 à 04:52, Yan Zhen a écrit :
> The devm_clk_hw_get_clk() function returns error pointers.
> It never returns NULL.  Update the check accordingly.
> 
> Fixes: 8737ec830ee3 ("clk: qcom: common: Add interconnect clocks support")'
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> ---
> 
> Changes in v3:
> - Providing a "fixes" tag blaming the commit.
> 
>   drivers/clk/qcom/common.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/qcom/common.c b/drivers/clk/qcom/common.c
> index 33cc1f73c69d..5a9e653916ea 100644
> --- a/drivers/clk/qcom/common.c
> +++ b/drivers/clk/qcom/common.c
> @@ -273,8 +273,8 @@ static int qcom_cc_icc_register(struct device *dev,
>   		icd[i].slave_id = desc->icc_hws[i].slave_id;
>   		hws = &desc->clks[desc->icc_hws[i].clk_id]->hw;
>   		icd[i].clk = devm_clk_hw_get_clk(dev, hws, "icc");
> -		if (!icd[i].clk)
> -			return dev_err_probe(dev, -ENOENT,
> +		if (IS_ERR(icd[i].clk))
> +			return dev_err_probe(dev, PTR_ERR(icd[i].clk),
>   					     "(%d) clock entry is null\n", i);

Nitpick: Maybe the message could be updated as-well?

CJ

>   		icd[i].name = clk_hw_get_name(hws);
>   	}


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

* Re: [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk()
  2024-08-29  9:06   ` Dmitry Baryshkov
@ 2024-08-29 17:42     ` Stephen Boyd
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2024-08-29 17:42 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Yan Zhen, andersson, mturquette, linux-arm-msm, linux-clk,
	linux-kernel, opensource.kernel

Quoting Dmitry Baryshkov (2024-08-29 02:06:51)
> On Tue, Aug 27, 2024 at 11:18:10AM GMT, Stephen Boyd wrote:
> > Quoting Yan Zhen (2024-08-26 19:52:52)
> > > The devm_clk_hw_get_clk() function returns error pointers.
> > > It never returns NULL.  Update the check accordingly.
> > 
> > It can return NULL if the 'hw' pointer passed in is NULL.
> 
> No, it will crash:
> 
>         WARN_ON_ONCE(dev != hw->core->dev);
> 
> Furthermore, clk_hw_get_clk() also doesn't have NULL checks and will
> crash if NULL is passed as hw.

Ah, thanks. I misread it as clk_hw_create_clk().

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

end of thread, other threads:[~2024-08-29 17:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-27  2:52 [PATCH v3] clk: qcom: Fix error checking for devm_clk_hw_get_clk() Yan Zhen
2024-08-27 18:18 ` Stephen Boyd
2024-08-27 20:08   ` Markus Elfring
2024-08-29  9:06   ` Dmitry Baryshkov
2024-08-29 17:42     ` Stephen Boyd
2024-08-29  9:07 ` Dmitry Baryshkov
2024-08-29 16:59 ` Christophe JAILLET

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