* Re: [PATCH 0/3] Input: clear the wake IRQ on unbind
[not found] <20261125072124.2997511-1-prasanth.r@lineo.co.jp>
@ 2026-11-26 8:21 ` Dmitry Torokhov
2026-11-28 23:25 ` [PATCH] PM: wakeirq: Clear driver wake IRQs " Prasanth R
0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Torokhov @ 2026-11-26 8:21 UTC (permalink / raw)
To: Prasanth R
Cc: linux-input, Hans de Goede, Chen-Yu Tsai, Jernej Skrabec,
Samuel Holland, Support Opensource, linux-arm-kernel, linux-sunxi,
Rafael J. Wysocki, Pavel Machek, Len Brown, linux-pm,
Greg Kroah-Hartman, Danilo Krummrich, Johan Hovold, driver-core
Hi Prasanth,
On Wed, Nov 25, 2026 at 04:21:21PM +0900, Prasanth R wrote:
> These drivers set a wake IRQ with dev_pm_set_wake_irq() and never clear
> it. After unbind and bind, dev_pm_set_wake_irq() warns "wake irq already
> initialized" and returns -EEXIST.
>
> Switch them to the device-managed helpers.
Adding PM and driver core maintainers to the thread.
I wonder why clearing the wake IRQ cannot be done automatically for all
drivers on unbind, for example in device_unbind_cleanup() alongside
pm_runtime_reinit() and dev_pm_set_driver_flags().
The only case I see where a wake IRQ is attached at device registration
time rather than by a bound driver (or bus probe()) is PCI OF WAKE# in
drivers/pci/of.c:pci_configure_wake_irq(). That could be distinguished
by checking dev->driver when attaching the wake IRQ, or via an explicit
flag, so device_unbind_cleanup() only clears driver-bound wake IRQs.
Handling this in the core would save us from having to hunt down and
convert individual drivers to devm_pm_set_wake_irq() across the tree,
and would also fix buses like SPI that set up wake IRQs in probe() but
do not clear them on remove.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] PM: wakeirq: Clear driver wake IRQs on unbind
2026-11-26 8:21 ` [PATCH 0/3] Input: clear the wake IRQ on unbind Dmitry Torokhov
@ 2026-11-28 23:25 ` Prasanth R
0 siblings, 0 replies; 2+ messages in thread
From: Prasanth R @ 2026-11-28 23:25 UTC (permalink / raw)
To: Rafael J . Wysocki, Greg Kroah-Hartman
Cc: Dmitry Torokhov, Danilo Krummrich, Johan Hovold, Pavel Machek,
Len Brown, Hans de Goede, Chen-Yu Tsai, Jernej Skrabec,
Samuel Holland, Support Opensource, Alexandre Belloni,
Paul Cercueil, Frank Li, Marco Felsch, driver-core, linux-pm,
linux-input, linux-rtc, linux-arm-kernel, linux-sunxi, Prasanth R
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@gmail.com>
Link: https://lore.kernel.org/r/20261125072026.2997493-1-prasanth.r@lineo.co.jp
Signed-off-by: Prasanth R <prasanth.r@lineo.co.jp>
---
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)
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-28 23:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261125072124.2997511-1-prasanth.r@lineo.co.jp>
2026-11-26 8:21 ` [PATCH 0/3] Input: clear the wake IRQ on unbind Dmitry Torokhov
2026-11-28 23:25 ` [PATCH] PM: wakeirq: Clear driver wake IRQs " Prasanth R
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox