2021-06-17 14:44:37

by Dan Carpenter

[permalink] [raw]
Subject: [PATCH 2/2] clk: renesas: Avoid mixing error pointers and NULL

These functions accidentally return both error pointers and NULL when
there is an error. It doesn't cause a problem but it is confusing and
seems unintentional.

Signed-off-by: Dan Carpenter <[email protected]>
---
drivers/clk/renesas/renesas-rzg2l-cpg.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/renesas/renesas-rzg2l-cpg.c b/drivers/clk/renesas/renesas-rzg2l-cpg.c
index 7ba36f19896f..83b58e1cb78f 100644
--- a/drivers/clk/renesas/renesas-rzg2l-cpg.c
+++ b/drivers/clk/renesas/renesas-rzg2l-cpg.c
@@ -124,7 +124,7 @@ rzg2l_cpg_div_clk_register(const struct cpg_core_clk *core,
core->flag, &priv->rmw_lock);

if (IS_ERR(clk_hw))
- return NULL;
+ return ERR_CAST(clk_hw);

return clk_hw->clk;
}
@@ -174,17 +174,14 @@ rzg2l_cpg_pll_clk_register(const struct cpg_core_clk *core,
struct clk_init_data init;
const char *parent_name;
struct pll_clk *pll_clk;
- struct clk *clk;

parent = clks[core->parent & 0xffff];
if (IS_ERR(parent))
return ERR_CAST(parent);

pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL);
- if (!pll_clk) {
- clk = ERR_PTR(-ENOMEM);
- return NULL;
- }
+ if (!pll_clk)
+ return ERR_PTR(-ENOMEM);

parent_name = __clk_get_name(parent);
init.name = core->name;
--
2.30.2


2021-06-17 18:24:43

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: RE: [PATCH 2/2] clk: renesas: Avoid mixing error pointers and NULL

Hi Dan,

Thank you for the patch.

> -----Original Message-----
> From: Dan Carpenter <[email protected]>
> Sent: 17 June 2021 15:15
> To: Geert Uytterhoeven <[email protected]>; Prabhakar Mahadev Lad <prabhakar.mahadev-
> [email protected]>
> Cc: Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; linux-renesas-
> [email protected]; [email protected]; [email protected]; kernel-
> [email protected]
> Subject: [PATCH 2/2] clk: renesas: Avoid mixing error pointers and NULL
>
> These functions accidentally return both error pointers and NULL when there is an error. It doesn't
> cause a problem but it is confusing and seems unintentional.
>
> Signed-off-by: Dan Carpenter <[email protected]>
> ---
> drivers/clk/renesas/renesas-rzg2l-cpg.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>

Reviewed-by: Lad Prabhakar <[email protected]>

Cheers,
Prabhakar

> diff --git a/drivers/clk/renesas/renesas-rzg2l-cpg.c b/drivers/clk/renesas/renesas-rzg2l-cpg.c
> index 7ba36f19896f..83b58e1cb78f 100644
> --- a/drivers/clk/renesas/renesas-rzg2l-cpg.c
> +++ b/drivers/clk/renesas/renesas-rzg2l-cpg.c
> @@ -124,7 +124,7 @@ rzg2l_cpg_div_clk_register(const struct cpg_core_clk *core,
> core->flag, &priv->rmw_lock);
>
> if (IS_ERR(clk_hw))
> - return NULL;
> + return ERR_CAST(clk_hw);
>
> return clk_hw->clk;
> }
> @@ -174,17 +174,14 @@ rzg2l_cpg_pll_clk_register(const struct cpg_core_clk *core,
> struct clk_init_data init;
> const char *parent_name;
> struct pll_clk *pll_clk;
> - struct clk *clk;
>
> parent = clks[core->parent & 0xffff];
> if (IS_ERR(parent))
> return ERR_CAST(parent);
>
> pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL);
> - if (!pll_clk) {
> - clk = ERR_PTR(-ENOMEM);
> - return NULL;
> - }
> + if (!pll_clk)
> + return ERR_PTR(-ENOMEM);
>
> parent_name = __clk_get_name(parent);
> init.name = core->name;
> --
> 2.30.2

2021-06-18 12:41:27

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 2/2] clk: renesas: Avoid mixing error pointers and NULL

Hi Dan,

On Thu, Jun 17, 2021 at 4:15 PM Dan Carpenter <[email protected]> wrote:
> These functions accidentally return both error pointers and NULL when
> there is an error. It doesn't cause a problem but it is confusing and
> seems unintentional.
>
> Signed-off-by: Dan Carpenter <[email protected]>

Reviewed-by: Geert Uytterhoeven <[email protected]>
i.e. will queue in renesas-clk-for-v5.15.

> --- a/drivers/clk/renesas/renesas-rzg2l-cpg.c
> +++ b/drivers/clk/renesas/renesas-rzg2l-cpg.c
> @@ -124,7 +124,7 @@ rzg2l_cpg_div_clk_register(const struct cpg_core_clk *core,
> core->flag, &priv->rmw_lock);
>
> if (IS_ERR(clk_hw))
> - return NULL;
> + return ERR_CAST(clk_hw);
>
> return clk_hw->clk;
> }
> @@ -174,17 +174,14 @@ rzg2l_cpg_pll_clk_register(const struct cpg_core_clk *core,
> struct clk_init_data init;
> const char *parent_name;
> struct pll_clk *pll_clk;
> - struct clk *clk;
>
> parent = clks[core->parent & 0xffff];
> if (IS_ERR(parent))
> return ERR_CAST(parent);
>
> pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL);
> - if (!pll_clk) {
> - clk = ERR_PTR(-ENOMEM);
> - return NULL;
> - }
> + if (!pll_clk)
> + return ERR_PTR(-ENOMEM);

This part I already have, by virtue of
https://lore.kernel.org/r/[email protected]

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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