[PATCH v1 3/3] PM: sleep: Introduce pm_sleep_transition_in_progress()

From: Rafael J. Wysocki
Date: Fri May 09 2025 - 09:04:54 EST


From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>

The "suspend in progress" check in device_wakeup_enable() does not
cover hibernation, but arguably it should do that, so introduce
pm_sleep_transition_in_progress() covering transitions during both
system suspend and hibernation to use in there and use it also in
pm_debug_messages_should_print().

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
---
drivers/base/power/wakeup.c | 2 +-
include/linux/suspend.h | 4 ++++
kernel/power/main.c | 8 ++++++--
3 files changed, 11 insertions(+), 3 deletions(-)

--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -337,7 +337,7 @@
if (!dev || !dev->power.can_wakeup)
return -EINVAL;

- if (pm_suspend_in_progress())
+ if (pm_sleep_transition_in_progress())
dev_dbg(dev, "Suspicious %s() during system transition!\n", __func__);

ws = wakeup_source_register(dev, dev_name(dev));
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -475,6 +475,8 @@
extern unsigned int lock_system_sleep(void);
extern void unlock_system_sleep(unsigned int);

+extern bool pm_sleep_transition_in_progress(void);
+
#else /* !CONFIG_PM_SLEEP */

static inline int register_pm_notifier(struct notifier_block *nb)
@@ -503,6 +505,8 @@
static inline unsigned int lock_system_sleep(void) { return 0; }
static inline void unlock_system_sleep(unsigned int flags) {}

+static inline bool pm_sleep_transition_in_progress(void) { return false; }
+
#endif /* !CONFIG_PM_SLEEP */

#ifdef CONFIG_PM_SLEEP_DEBUG
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -609,12 +609,16 @@

power_attr_ro(pm_wakeup_irq);

+bool pm_sleep_transition_in_progress(void)
+{
+ return pm_suspend_in_progress() || hibernation_in_progress();
+}
+
bool pm_debug_messages_on __read_mostly;

bool pm_debug_messages_should_print(void)
{
- return pm_debug_messages_on && (pm_suspend_in_progress() ||
- hibernation_in_progress());
+ return pm_debug_messages_on && pm_sleep_transition_in_progress();
}
EXPORT_SYMBOL_GPL(pm_debug_messages_should_print);