Clk_gpio should be disabled in all error paths in the code that
follws, including the case when either gpiochip_add_data() or
gpiochip_irqchip_add() fail. To simplify things fix this by using
devm_add_action() to disable corresponding clock in case of any erros
as well as driver/device removal.

Signed-off-by: Andrey Smirnov <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Chris Healy <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Heiner Kallweit <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
 drivers/gpio/gpio-vf610.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 78c1f8ebbe8f..f7445468677d 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -289,6 +289,10 @@ static int vf610_gpio_probe(struct platform_device *pdev)
                ret = clk_prepare_enable(port->clk_gpio);
                if (ret)
                        return ret;
+               ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk,
+                                              port->clk_gpio);
+               if (ret)
+                       return ret;
        } else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) {
                return PTR_ERR(port->clk_gpio);
        }
@@ -345,8 +349,6 @@ static int vf610_gpio_remove(struct platform_device *pdev)
        struct vf610_gpio_port *port = platform_get_drvdata(pdev);
 
        gpiochip_remove(&port->gc);
-       if (!IS_ERR(port->clk_gpio))
-               clk_disable_unprepare(port->clk_gpio);
 
        return 0;
 }
-- 
2.20.1

Reply via email to