| Message ID | 20261105-gpio-vf610-fixes-v3-3-504e19de5ad5@nxp.com |
|---|---|
| State | New |
| Headers | show |
| Series | gpio: vf610: fix clocks and misc cleanup | expand |
On Thu, Nov 05, 2026 at 11:53:01AM +0800, Peng Fan (OSS) wrote: > From: Peng Fan <peng.fan@nxp.com> > > Replace the manual clock acquisition, enable and cleanup sequences with > devm_clk_get_optional_enabled() for both the port and gpio clocks. The > helper treats a missing clock as NULL and automatically disables and > unprepares the clocks on driver unbind, so the vf610_gpio_disable_clk() > helper is no longer needed. > > Unlike the previous code, propagate all errors from the helper, > including clk_prepare_enable() failures. The old code only tolerated > lookup errors and failed probe when enabling the clock failed; continuing > with a disabled clock could fault when accessing the PORT/GPIO registers. > The optional helper already covers the "clock not described" case, so > there is no need to silently ignore other errors. > > The clock pointers are only needed during probe now that devm manages > their lifetime, so drop them from struct vf610_gpio_port and use a local > variable instead. > > Signed-off-by: Peng Fan <peng.fan@nxp.com> > --- Reviewed-by: Frank Li <Frank.Li@nxp.com> > drivers/gpio/gpio-vf610.c | 46 +++++++++------------------------------------- > 1 file changed, 9 insertions(+), 37 deletions(-) > > diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c > index c1c562071c0d..9ebb4469fd15 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; > }; > > @@ -206,11 +204,6 @@ static const struct irq_chip vf610_irqchip = { > GPIOCHIP_IRQ_RESOURCE_HELPERS, > }; > > -static void vf610_gpio_disable_clk(void *data) > -{ > - clk_disable_unprepare(data); > -} > - > static int vf610_gpio_probe(struct platform_device *pdev) > { > struct gpio_generic_chip_config config; > @@ -218,6 +211,7 @@ static int vf610_gpio_probe(struct platform_device *pdev) > struct vf610_gpio_port *port; > struct gpio_chip *gc; > struct gpio_irq_chip *girq; > + struct clk *clk; > unsigned long flags; > int i; > int ret; > @@ -261,37 +255,15 @@ 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 = devm_clk_get_optional_enabled(dev, "port"); > + if (IS_ERR(clk)) > + return dev_err_probe(dev, PTR_ERR(clk), > + "failed to get/enable port clock\n"); > > - 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 = devm_clk_get_optional_enabled(dev, "gpio"); > + if (IS_ERR(clk)) > + return dev_err_probe(dev, PTR_ERR(clk), > + "failed to get/enable gpio clock\n"); > > gc = &port->chip.gc; > flags = GPIO_GENERIC_PINCTRL_BACKEND; > > -- > 2.51.0 > >
On Thu, Nov 5, 2026 at 4:56 AM Peng Fan (OSS) <peng.fan@oss.nxp.com> wrote: > From: Peng Fan <peng.fan@nxp.com> > > Replace the manual clock acquisition, enable and cleanup sequences with > devm_clk_get_optional_enabled() for both the port and gpio clocks. The > helper treats a missing clock as NULL and automatically disables and > unprepares the clocks on driver unbind, so the vf610_gpio_disable_clk() > helper is no longer needed. > > Unlike the previous code, propagate all errors from the helper, > including clk_prepare_enable() failures. The old code only tolerated > lookup errors and failed probe when enabling the clock failed; continuing > with a disabled clock could fault when accessing the PORT/GPIO registers. > The optional helper already covers the "clock not described" case, so > there is no need to silently ignore other errors. > > The clock pointers are only needed during probe now that devm manages > their lifetime, so drop them from struct vf610_gpio_port and use a local > variable instead. > > Signed-off-by: Peng Fan <peng.fan@nxp.com> Reviewed-by: Linus Walleij <linusw@kernel.org> Yours, Linus Walleij
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c index c1c562071c0d..9ebb4469fd15 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; }; @@ -206,11 +204,6 @@ static const struct irq_chip vf610_irqchip = { GPIOCHIP_IRQ_RESOURCE_HELPERS, }; -static void vf610_gpio_disable_clk(void *data) -{ - clk_disable_unprepare(data); -} - static int vf610_gpio_probe(struct platform_device *pdev) { struct gpio_generic_chip_config config; @@ -218,6 +211,7 @@ static int vf610_gpio_probe(struct platform_device *pdev) struct vf610_gpio_port *port; struct gpio_chip *gc; struct gpio_irq_chip *girq; + struct clk *clk; unsigned long flags; int i; int ret; @@ -261,37 +255,15 @@ 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 = devm_clk_get_optional_enabled(dev, "port"); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), + "failed to get/enable port clock\n"); - 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 = devm_clk_get_optional_enabled(dev, "gpio"); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), + "failed to get/enable gpio clock\n"); gc = &port->chip.gc; flags = GPIO_GENERIC_PINCTRL_BACKEND;