diff mbox series

[v8,07/16] gpio: vf610: Simplify error handling in probe

Message ID 20220314141643.22184-8-u.kleine-koenig@pengutronix.de (mailing list archive)
State Not Applicable, archived
Headers show
Series clk: provide new devm helpers for prepared and enabled clocks | expand

Commit Message

Uwe Kleine-König March 14, 2022, 2:16 p.m. UTC
Instead of manually enabling and registering a devm cleanup handler that
disables the clock, use devm_clk_get_enabled(). Also replace the handling
of the optional clocks by using a variant of clk_get_optional().

The resulting code is a tad stricter than the previous code as errors from
clk_get() (apart from -ENOENT) make vf610_gpio_probe() return an error.
This is however an improvement.

Also make the clock pointers local variables instead of a member of driver
data, as they are only used in .probe().

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/gpio/gpio-vf610.c | 45 +++++++--------------------------------
 1 file changed, 8 insertions(+), 37 deletions(-)

Comments

Bartosz Golaszewski March 14, 2022, 3:01 p.m. UTC | #1
On Mon, Mar 14, 2022 at 3:17 PM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> Instead of manually enabling and registering a devm cleanup handler that
> disables the clock, use devm_clk_get_enabled(). Also replace the handling
> of the optional clocks by using a variant of clk_get_optional().
>
> The resulting code is a tad stricter than the previous code as errors from
> clk_get() (apart from -ENOENT) make vf610_gpio_probe() return an error.
> This is however an improvement.
>
> Also make the clock pointers local variables instead of a member of driver
> data, as they are only used in .probe().
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/gpio/gpio-vf610.c | 45 +++++++--------------------------------
>  1 file changed, 8 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
> index 20780c35da1b..4a6ad2e8d1a1 100644
> --- a/drivers/gpio/gpio-vf610.c
> +++ b/drivers/gpio/gpio-vf610.c
> @@ -34,8 +34,6 @@ struct vf610_gpio_port {
>         void __iomem *gpio_base;
>         const struct fsl_gpio_soc_data *sdata;
>         u8 irqc[VF610_GPIO_PER_PORT];
> -       struct clk *clk_port;
> -       struct clk *clk_gpio;
>         int irq;
>  };
>
> @@ -232,11 +230,6 @@ static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
>         return 0;
>  }
>
> -static void vf610_gpio_disable_clk(void *data)
> -{
> -       clk_disable_unprepare(data);
> -}
> -
>  static int vf610_gpio_probe(struct platform_device *pdev)
>  {
>         struct device *dev = &pdev->dev;
> @@ -245,6 +238,8 @@ static int vf610_gpio_probe(struct platform_device *pdev)
>         struct gpio_chip *gc;
>         struct gpio_irq_chip *girq;
>         struct irq_chip *ic;
> +       struct clk *clk_port;
> +       struct clk *clk_gpio;
>         int i;
>         int ret;
>
> @@ -265,37 +260,13 @@ static int vf610_gpio_probe(struct platform_device *pdev)
>         if (port->irq < 0)
>                 return port->irq;
>
> -       port->clk_port = devm_clk_get(dev, "port");
> -       ret = PTR_ERR_OR_ZERO(port->clk_port);
> -       if (!ret) {
> -               ret = clk_prepare_enable(port->clk_port);
> -               if (ret)
> -                       return ret;
> -               ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk,
> -                                              port->clk_port);
> -               if (ret)
> -                       return ret;
> -       } else if (ret == -EPROBE_DEFER) {
> -               /*
> -                * Percolate deferrals, for anything else,
> -                * just live without the clocking.
> -                */
> -               return ret;
> -       }
> +       clk_port = devm_clk_get_optional_enabled(dev, "port");
> +       if (IS_ERR(clk_port))
> +               return PTR_ERR(clk_port);
>
> -       port->clk_gpio = devm_clk_get(dev, "gpio");
> -       ret = PTR_ERR_OR_ZERO(port->clk_gpio);
> -       if (!ret) {
> -               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 (ret == -EPROBE_DEFER) {
> -               return ret;
> -       }
> +       clk_gpio = devm_clk_get_optional_enabled(dev, "gpio");
> +       if (IS_ERR(clk_gpio))
> +               return PTR_ERR(clk_gpio);
>
>         gc = &port->gc;
>         gc->parent = dev;
> --
> 2.35.1
>

Acked-by: Bartosz Golaszewski <brgl@bgdev.pl>
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 20780c35da1b..4a6ad2e8d1a1 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -34,8 +34,6 @@  struct vf610_gpio_port {
 	void __iomem *gpio_base;
 	const struct fsl_gpio_soc_data *sdata;
 	u8 irqc[VF610_GPIO_PER_PORT];
-	struct clk *clk_port;
-	struct clk *clk_gpio;
 	int irq;
 };
 
@@ -232,11 +230,6 @@  static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
 	return 0;
 }
 
-static void vf610_gpio_disable_clk(void *data)
-{
-	clk_disable_unprepare(data);
-}
-
 static int vf610_gpio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -245,6 +238,8 @@  static int vf610_gpio_probe(struct platform_device *pdev)
 	struct gpio_chip *gc;
 	struct gpio_irq_chip *girq;
 	struct irq_chip *ic;
+	struct clk *clk_port;
+	struct clk *clk_gpio;
 	int i;
 	int ret;
 
@@ -265,37 +260,13 @@  static int vf610_gpio_probe(struct platform_device *pdev)
 	if (port->irq < 0)
 		return port->irq;
 
-	port->clk_port = devm_clk_get(dev, "port");
-	ret = PTR_ERR_OR_ZERO(port->clk_port);
-	if (!ret) {
-		ret = clk_prepare_enable(port->clk_port);
-		if (ret)
-			return ret;
-		ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk,
-					       port->clk_port);
-		if (ret)
-			return ret;
-	} else if (ret == -EPROBE_DEFER) {
-		/*
-		 * Percolate deferrals, for anything else,
-		 * just live without the clocking.
-		 */
-		return ret;
-	}
+	clk_port = devm_clk_get_optional_enabled(dev, "port");
+	if (IS_ERR(clk_port))
+		return PTR_ERR(clk_port);
 
-	port->clk_gpio = devm_clk_get(dev, "gpio");
-	ret = PTR_ERR_OR_ZERO(port->clk_gpio);
-	if (!ret) {
-		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 (ret == -EPROBE_DEFER) {
-		return ret;
-	}
+	clk_gpio = devm_clk_get_optional_enabled(dev, "gpio");
+	if (IS_ERR(clk_gpio))
+		return PTR_ERR(clk_gpio);
 
 	gc = &port->gc;
 	gc->parent = dev;