[PATCH v7 07/12] gpio: mxc: use __free guard for runtime PM cleanup
Frank Li
Frank.li at oss.nxp.com
Tue Oct 27 07:12:23 PDT 2026
On Tue, Oct 27, 2026 at 08:09:34PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan at nxp.com>
>
> Use a scope-based cleanup guard to disable runtime PM and drop the
> probe-scoped pm_runtime_get_noresume() reference on error paths. Disarm
> it with retain_and_null_ptr() before the success-path
> pm_runtime_put_autosuspend().
>
> The guard keeps the required order: pm_runtime_disable() runs before
> pm_runtime_put_noidle(), so dropping the reference cannot trigger a
> runtime suspend callback while probe is still unwinding.
>
> Signed-off-by: Peng Fan <peng.fan at nxp.com>
> ---
Reviewed-by: Frank Li <Frank.Li at nxp.com>
> drivers/gpio/gpio-mxc.c | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
> index 21c74b244c1f..68857730b5e3 100644
> --- a/drivers/gpio/gpio-mxc.c
> +++ b/drivers/gpio/gpio-mxc.c
> @@ -28,6 +28,20 @@
> #include <linux/of.h>
> #include <linux/bug.h>
>
> +static void mxc_gpio_pm_release(struct device *dev)
> +{
> + if (!dev)
> + return;
> +
> + if (pm_runtime_enabled(dev))
> + pm_runtime_disable(dev);
> +
> + pm_runtime_put_noidle(dev);
> +}
> +
> +DEFINE_FREE(mxc_gpio_pm_cleanup, struct device *,
> + mxc_gpio_pm_release(_T))
> +
> #define IMX_SCU_WAKEUP_OFF 0
> #define IMX_SCU_WAKEUP_LOW_LVL 4
> #define IMX_SCU_WAKEUP_FALL_EDGE 5
> @@ -487,6 +501,9 @@ static int mxc_gpio_probe(struct platform_device *pdev)
> return PTR_ERR(port->clk);
>
> pm_runtime_get_noresume(dev);
> +
> + struct device *pm_guard __free(mxc_gpio_pm_cleanup) = dev;
> +
> pm_runtime_set_active(dev);
> pm_runtime_enable(dev);
>
> @@ -562,6 +579,8 @@ static int mxc_gpio_probe(struct platform_device *pdev)
> mxc_update_irq_chained_handler(port, true);
>
> platform_set_drvdata(pdev, port);
> +
> + retain_and_null_ptr(pm_guard);
> pm_runtime_put_autosuspend(dev);
>
> return 0;
> @@ -569,8 +588,6 @@ static int mxc_gpio_probe(struct platform_device *pdev)
> out_irqdomain_remove:
> irq_domain_remove(port->domain);
> out_bgio:
> - pm_runtime_disable(dev);
> - pm_runtime_put_noidle(dev);
> dev_info(dev, "%s failed with errno %d\n", __func__, err);
> return err;
> }
>
> --
> 2.51.0
>
>
More information about the linux-arm-kernel
mailing list