[PATCH 15/20] gpio/rockchip: disable and put clocks when gpiolib register failed

Jianqun Xu posted 20 patches 3 years, 6 months ago
[PATCH 15/20] gpio/rockchip: disable and put clocks when gpiolib register failed
Posted by Jianqun Xu 3 years, 6 months ago
When gpiolib register failed, the clocks should be disabled and put.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 drivers/gpio/gpio-rockchip.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 4fcd75d710c1..09ed5c880dde 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -746,14 +746,21 @@ static int rockchip_gpio_probe(struct platform_device *pdev)
 
 	ret = rockchip_gpiolib_register(bank);
 	if (ret) {
-		clk_disable_unprepare(bank->clk);
-		return ret;
+		dev_err(bank->dev, "Failed to register gpio %d\n", ret);
+		goto err_put_clk;
 	}
 
 	platform_set_drvdata(pdev, bank);
 	dev_info(dev, "probed %pOF\n", np);
 
 	return 0;
+err_put_clk:
+	clk_put(bank->clk);
+	clk_put(bank->db_clk);
+	clk_disable_unprepare(bank->clk);
+	clk_disable_unprepare(bank->db_clk);
+
+	return ret;
 }
 
 static int rockchip_gpio_remove(struct platform_device *pdev)
-- 
2.25.1
Re: [PATCH 15/20] gpio/rockchip: disable and put clocks when gpiolib register failed
Posted by Linus Walleij 3 years, 6 months ago
On Tue, Sep 20, 2022 at 12:31 PM Jianqun Xu <jay.xu@rock-chips.com> wrote:

> When gpiolib register failed, the clocks should be disabled and put.
>
> Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
(...)
> +err_put_clk:
> +       clk_put(bank->clk);
> +       clk_put(bank->db_clk);
> +       clk_disable_unprepare(bank->clk);
> +       clk_disable_unprepare(bank->db_clk);

Always clk_disable_unprepare() before clk_put().

I think you can drop clk_put() if you switch to devres dev_clk_get()
instead.

Yours,
Linus Walleij
Re: [PATCH 15/20] gpio/rockchip: disable and put clocks when gpiolib register failed
Posted by Linus Walleij 3 years, 6 months ago
On Tue, Oct 4, 2022 at 9:16 AM Linus Walleij <linus.walleij@linaro.org> wrote:

> On Tue, Sep 20, 2022 at 12:31 PM Jianqun Xu <jay.xu@rock-chips.com> wrote:
>
> > When gpiolib register failed, the clocks should be disabled and put.
> >
> > Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
> (...)
> > +err_put_clk:
> > +       clk_put(bank->clk);
> > +       clk_put(bank->db_clk);
> > +       clk_disable_unprepare(bank->clk);
> > +       clk_disable_unprepare(bank->db_clk);
>
> Always clk_disable_unprepare() before clk_put().
>
> I think you can drop clk_put() if you switch to devres dev_clk_get()
> instead.

devm_clk_get() I mean.

Yours,
Linus Walleij