Re: [PATCH] gpio: mvebu: use devm_clk_get_optional_enabled()

From: Bartosz Golaszewski

Date: Wed Jul 08 2026 - 07:57:24 EST


On Wed, 8 Jul 2026 01:06:51 +0200, Rosen Penev <rosenp@xxxxxxxxx> said:
> The clock is obtained without doing any sort of cleanup on remove or
> anywhere else. Use the proper function to handle this. When it fails
> with -EPROBE_DEFER for example, return so that it can be handled. When
> the clock is not found, it's NULL and not a PTR_ERR. Handle that as
> well.
>
> Fixes: 757642f9a584e ("gpio: mvebu: Add limited PWM support")
> Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>

Looks like someone beat you to it[1] but your patch seems to contain more.

> ---
> drivers/gpio/gpio-mvebu.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> index 329275d6518c..cdf7eb46ae5f 100644
> --- a/drivers/gpio/gpio-mvebu.c
> +++ b/drivers/gpio/gpio-mvebu.c
> @@ -833,8 +833,8 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
> offset = 0;
> }
>
> - if (IS_ERR(mvchip->clk))
> - return PTR_ERR(mvchip->clk);
> + if (!mvchip->clk)
> + return -ENODEV;

Why -ENODEV? Is the clock optional or not?

>
> chip = devm_pwmchip_alloc(dev, mvchip->chip.ngpio, sizeof(*mvpwm));
> if (IS_ERR(chip))
> @@ -1194,10 +1194,10 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
> return id;
> }
>
> - mvchip->clk = devm_clk_get(&pdev->dev, NULL);
> /* Not all SoCs require a clock.*/
> - if (!IS_ERR(mvchip->clk))
> - clk_prepare_enable(mvchip->clk);
> + mvchip->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
> + if (IS_ERR(mvchip->clk))
> + return PTR_ERR(mvchip->clk);
>
> mvchip->soc_variant = soc_variant;
> mvchip->chip.label = dev_name(&pdev->dev);
> --
> 2.55.0
>
>

Bart

[1] https://lore.kernel.org/all/20260707160030.385137-1-dbgh9129@xxxxxxxxx/