[PATCH v4 3/4] PM: hibernate: notify on image write failure

Haowen Tu <[email protected]>
Newsgroups org.kernel.vger.linux-pm,org.kernel.vger.linux-kernel,org.kernel.vger.linux-media,org.kernel.vger.linux-usb
Message-ID <e2b88a0b33797b36ce4b1c8340a9f33d844fb79d.1785226280.git.tuhaowen@uniontech.com>
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 <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.