* [PATCH] clk: renesas: rcar-usb2-clock-sel: Fix error handling in rcar_usb2_clock_sel_probe
@ 2021-04-12 7:50 Dinghao Liu
2021-04-12 9:02 ` Geert Uytterhoeven
0 siblings, 1 reply; 2+ messages in thread
From: Dinghao Liu @ 2021-04-12 7:50 UTC (permalink / raw)
To: dinghao.liu, kjlu
Cc: Geert Uytterhoeven, Michael Turquette, Stephen Boyd,
linux-renesas-soc, linux-clk, linux-kernel
When clk_get_rate() fails, a pairing PM usage counter decrement
and disable is required to prevent refcount leak. It's the same
for the subsequent error paths. When of_clk_add_hw_provider()
fails, we need to unregister clk_hw.
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
drivers/clk/renesas/rcar-usb2-clock-sel.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/renesas/rcar-usb2-clock-sel.c b/drivers/clk/renesas/rcar-usb2-clock-sel.c
index 3abafd78f7c8..ad7bd50b9d1b 100644
--- a/drivers/clk/renesas/rcar-usb2-clock-sel.c
+++ b/drivers/clk/renesas/rcar-usb2-clock-sel.c
@@ -180,7 +180,8 @@ static int rcar_usb2_clock_sel_probe(struct platform_device *pdev)
if (!priv->extal && !priv->xtal) {
dev_err(dev, "This driver needs usb_extal or usb_xtal\n");
- return -ENOENT;
+ ret = -ENOENT;
+ goto pm_put;
}
platform_set_drvdata(pdev, priv);
@@ -194,10 +195,23 @@ static int rcar_usb2_clock_sel_probe(struct platform_device *pdev)
priv->hw.init = &init;
clk = clk_register(NULL, &priv->hw);
- if (IS_ERR(clk))
- return PTR_ERR(clk);
+ if (IS_ERR(clk)) {
+ ret = PTR_ERR(clk);
+ goto pm_put;
+ }
+
+ ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &priv->hw);
+ if (ret)
+ goto clk_unregister;
+
+ return 0;
- return of_clk_add_hw_provider(np, of_clk_hw_simple_get, &priv->hw);
+clk_unregister:
+ clk_hw_unregister(&priv->hw);
+pm_put:
+ pm_runtime_put(dev);
+ pm_runtime_disable(dev);
+ return ret;
}
static const struct dev_pm_ops rcar_usb2_clock_sel_pm_ops = {
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] clk: renesas: rcar-usb2-clock-sel: Fix error handling in rcar_usb2_clock_sel_probe
2021-04-12 7:50 [PATCH] clk: renesas: rcar-usb2-clock-sel: Fix error handling in rcar_usb2_clock_sel_probe Dinghao Liu
@ 2021-04-12 9:02 ` Geert Uytterhoeven
0 siblings, 0 replies; 2+ messages in thread
From: Geert Uytterhoeven @ 2021-04-12 9:02 UTC (permalink / raw)
To: Dinghao Liu
Cc: Kangjie Lu, Michael Turquette, Stephen Boyd, Linux-Renesas,
linux-clk, Linux Kernel Mailing List
Hi Dinghao,
On Mon, Apr 12, 2021 at 9:51 AM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:
> When clk_get_rate() fails, a pairing PM usage counter decrement
> and disable is required to prevent refcount leak. It's the same
> for the subsequent error paths. When of_clk_add_hw_provider()
> fails, we need to unregister clk_hw.
>
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
Thanks for your patch, which looks correct to me.
> --- a/drivers/clk/renesas/rcar-usb2-clock-sel.c
> +++ b/drivers/clk/renesas/rcar-usb2-clock-sel.c
> @@ -180,7 +180,8 @@ static int rcar_usb2_clock_sel_probe(struct platform_device *pdev)
>
> if (!priv->extal && !priv->xtal) {
> dev_err(dev, "This driver needs usb_extal or usb_xtal\n");
> - return -ENOENT;
> + ret = -ENOENT;
> + goto pm_put;
> }
As the code above doesn't rely on the device being powered yet, you
could move the pm_runtime_{enable,get_sync}() calls below the clock
checks instead.
>
> platform_set_drvdata(pdev, priv);
> @@ -194,10 +195,23 @@ static int rcar_usb2_clock_sel_probe(struct platform_device *pdev)
> priv->hw.init = &init;
>
> clk = clk_register(NULL, &priv->hw);
> - if (IS_ERR(clk))
> - return PTR_ERR(clk);
> + if (IS_ERR(clk)) {
> + ret = PTR_ERR(clk);
> + goto pm_put;
> + }
> +
> + ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &priv->hw);
> + if (ret)
> + goto clk_unregister;
> +
> + return 0;
>
> - return of_clk_add_hw_provider(np, of_clk_hw_simple_get, &priv->hw);
> +clk_unregister:
> + clk_hw_unregister(&priv->hw);
The error path can be simplified by replacing the call to clk_register()
by a call to devm_clk_register(), to match the style of the other
initialization steps.
> +pm_put:
> + pm_runtime_put(dev);
> + pm_runtime_disable(dev);
> + return ret;
This part has to stay, of course.
> }
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-12 9:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 7:50 [PATCH] clk: renesas: rcar-usb2-clock-sel: Fix error handling in rcar_usb2_clock_sel_probe Dinghao Liu
2021-04-12 9:02 ` Geert Uytterhoeven
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.