[PATCH v4 3/4] PM: hibernate: notify on image write failure
From: Haowen Tu
Date: Wed Jul 29 2026 - 03:32:14 EST
Some drivers may defer device-specific resume work after the hibernation
snapshot has been created, because the system is expected to either write
the image and power off, or enter the test-resume path.
If writing the image fails, however, the original kernel continues
running. Add a PM_HIBERNATION_IMAGE_WRITE_FAILED notification after
swsusp_write() fails and before userspace is thawed, so drivers that
deferred resume work can recover their device state before userspace
observes it.
Signed-off-by: Haowen Tu <tuhaowen@xxxxxxxxxxxxx>
---
include/linux/suspend.h | 1 +
kernel/power/hibernate.c | 3 +++
2 files changed, 4 insertions(+)
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 2cebbec3e2f7..36a5b3a8cb38 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -441,6 +441,7 @@ static inline int is_hibernate_resume_dev(dev_t dev) { return 0; }
#define PM_POST_SUSPEND 0x0004 /* Suspend finished */
#define PM_RESTORE_PREPARE 0x0005 /* Going to restore a saved image */
#define PM_POST_RESTORE 0x0006 /* Restore failed */
+#define PM_HIBERNATION_IMAGE_WRITE_FAILED 0x0007 /* Image write failed */
extern struct mutex system_transition_mutex;
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 045d29f55011..592862fd45d4 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -890,6 +890,9 @@ int hibernate(void)
power_down();
}
pm_restore_gfp_mask();
+
+ if (error)
+ pm_notifier_call_chain(PM_HIBERNATION_IMAGE_WRITE_FAILED);
} else {
pm_pr_dbg("Hibernation image restored successfully.\n");
}
--
2.20.1