[PATCH] PM: wakeirq: Clear driver wake IRQs on unbind
Rafael J. Wysocki (Intel)
rafael at kernel.org
Wed Dec 2 12:57:13 PST 2026
On Sun, Nov 29, 2026 at 12:25 AM Prasanth R <ragaprasanth at gmail.com> wrote:
>
> A wake IRQ set up by a driver with dev_pm_set_wake_irq() or
> dev_pm_set_dedicated_wake_irq() stays attached to the device after the
> driver is unbound, unless the driver or its bus clears it. Many drivers
> don't, and unlike the I2C core, the platform and SPI buses don't either.
> When the driver is bound again, dev_pm_set_wake_irq() warns "wake irq
> already initialized" and returns -EEXIST. The same happens when probe
> fails after setting the wake IRQ, for example with -EPROBE_DEFER.
>
> Mark a wake IRQ that is set while a driver is bound, and clear it in
> device_unbind_cleanup(), which runs on unbind and after a failed probe.
> Wake IRQs set up without a driver, like the PCI WAKE# IRQ set when the
> device is registered, stay in place.
>
> Drivers and buses that already clear the wake IRQ, directly or with
> devm_pm_set_wake_irq(), are not affected: it is gone by then.
>
> Tested on an i.MX6Q SABRE-SD: the snvs RTC and power key drivers can be
> unbound and bound again through sysfs without changes to the drivers.
>
> Suggested-by: Dmitry Torokhov <dmitry.torokhov at gmail.com>
> Link: https://lore.kernel.org/r/20261125072026.2997493-1-prasanth.r@lineo.co.jp
> Signed-off-by: Prasanth R <prasanth.r at lineo.co.jp>
Applied a 7.5 material with one non-essential change below.
> ---
> Dmitry suggested doing this in the driver core instead of in each
> driver [1].
>
> - It fixes rebinding of the platform and SPI drivers in [1], for
> example rtc-snvs and snvs_pwrkey, which I tested.
> - Only wake IRQs set while a driver is bound are cleared. The PCI
> WAKE# IRQ, set in pci_device_add(), is kept.
> - I checked all 64 callers of the wake IRQ setters. None sets a wake
> IRQ on another device that has its own driver.
> - Wakeup sources from device_init_wakeup() are not changed. Drivers
> that check its return value, like rtc-atcrtc100, still need
> devm_device_init_wakeup() to bind again.
>
> I'm holding v2 of [1] until this is decided.
>
> [1] https://lore.kernel.org/r/20261125072026.2997493-1-prasanth.r@lineo.co.jp
>
> I used an AI assistant (Claude) to find this and write the change.
>
> drivers/base/dd.c | 1 +
> drivers/base/power/power.h | 3 +++
> drivers/base/power/wakeirq.c | 22 +++++++++++++++++++++-
> 3 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index 521232519..06ebe7ee8 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -596,6 +596,7 @@ static void device_unbind_cleanup(struct device *dev)
> if (dev->driver->p_cb.post_unbind_rust)
> dev->driver->p_cb.post_unbind_rust(dev);
> devres_release_all(dev);
> + dev_pm_clear_driver_wake_irq(dev);
> arch_teardown_dma_ops(dev);
> kfree(dev->dma_range_map);
> dev->dma_range_map = NULL;
> diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
> index 8823aceea..e8b7611ec 100644
> --- a/drivers/base/power/power.h
> +++ b/drivers/base/power/power.h
> @@ -30,6 +30,7 @@ extern u64 pm_runtime_active_time(struct device *dev);
> WAKE_IRQ_DEDICATED_MANAGED | \
> WAKE_IRQ_DEDICATED_REVERSE)
> #define WAKE_IRQ_DEDICATED_ENABLED BIT(3)
> +#define WAKE_IRQ_DRIVER_BOUND BIT(4)
I've renamed this new flag to WAKE_IRQ_CLEAR_ON_UNBIND.
Thanks!
>
> struct wake_irq {
> struct device *dev;
> @@ -44,6 +45,7 @@ extern void dev_pm_enable_wake_irq_check(struct device *dev,
> bool can_change_status);
> extern void dev_pm_disable_wake_irq_check(struct device *dev, bool cond_disable);
> extern void dev_pm_enable_wake_irq_complete(struct device *dev);
> +void dev_pm_clear_driver_wake_irq(struct device *dev);
>
> #ifdef CONFIG_PM_SLEEP
>
> @@ -90,6 +92,7 @@ static inline void pm_runtime_early_init(struct device *dev)
> static inline void pm_runtime_init(struct device *dev) {}
> static inline void pm_runtime_reinit(struct device *dev) {}
> static inline void pm_runtime_remove(struct device *dev) {}
> +static inline void dev_pm_clear_driver_wake_irq(struct device *dev) {}
>
> static inline int dpm_sysfs_add(struct device *dev) { return 0; }
> static inline void dpm_sysfs_remove(struct device *dev) {}
> diff --git a/drivers/base/power/wakeirq.c b/drivers/base/power/wakeirq.c
> index ad23f0fa5..6280c007c 100644
> --- a/drivers/base/power/wakeirq.c
> +++ b/drivers/base/power/wakeirq.c
> @@ -30,6 +30,10 @@ static int dev_pm_attach_wake_irq(struct device *dev, struct wake_irq *wirq)
> return -EEXIST;
> }
>
> + /* The driver core clears this wake IRQ when the driver goes away */
> + if (dev->driver)
> + wirq->status |= WAKE_IRQ_DRIVER_BOUND;
> +
> dev->power.wakeirq = wirq;
> device_wakeup_attach_irq(dev, wirq);
>
> @@ -106,6 +110,22 @@ void dev_pm_clear_wake_irq(struct device *dev)
> }
> EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq);
>
> +/**
> + * dev_pm_clear_driver_wake_irq - Clear a wake IRQ set while a driver was bound
> + * @dev: Device entry
> + *
> + * Called by the driver core after a driver is unbound or fails to probe.
> + * Wake IRQs set up without a driver, for example by the bus when the device
> + * is registered, stay in place.
> + */
> +void dev_pm_clear_driver_wake_irq(struct device *dev)
> +{
> + struct wake_irq *wirq = dev->power.wakeirq;
> +
> + if (wirq && (wirq->status & WAKE_IRQ_DRIVER_BOUND))
> + dev_pm_clear_wake_irq(dev);
> +}
> +
> static void devm_pm_clear_wake_irq(void *dev)
> {
> dev_pm_clear_wake_irq(dev);
> @@ -209,7 +229,7 @@ static int __dev_pm_set_dedicated_wake_irq(struct device *dev, int irq, unsigned
> if (err)
> goto err_free_irq;
>
> - wirq->status = WAKE_IRQ_DEDICATED_ALLOCATED | flag;
> + wirq->status |= WAKE_IRQ_DEDICATED_ALLOCATED | flag;
>
> return err;
>
> --
> 2.43.0
>
>
More information about the linux-arm-kernel
mailing list