Skip to content

Commit 69fccb3

Browse files
committed
PM: hibernate: add new api pm_hibernate_is_recovering()
JIRA: https://issues.redhat.com/browse/RHEL-113576 commit c2aaddb Author: Samuel Zhang <guoqing.zhang@amd.com> Date: Thu Jul 10 14:23:12 2025 +0800 PM: hibernate: add new api pm_hibernate_is_recovering() dev_pm_ops.thaw() is called in following cases: * normal case: after hibernation image has been created. * error case 1: creation of a hibernation image has failed. * error case 2: restoration from a hibernation image has failed. For normal case, it is called mainly for resume storage devices for saving the hibernation image. Other devices that are not involved in the image saving do not need to resume the device. But since there's no api to know which case thaw() is called, device drivers can't conditionally resume device in thaw(). The new pm_hibernate_is_recovering() is such a api to query if thaw() is called in normal case. Signed-off-by: Samuel Zhang <guoqing.zhang@amd.com> Acked-by: Rafael J. Wysocki <rafael@kernel.org> Link: https://lore.kernel.org/r/20250710062313.3226149-5-guoqing.zhang@amd.com Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: José Expósito <jexposit@redhat.com>
1 parent a3eb967 commit 69fccb3

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

drivers/base/power/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ static pm_message_t pm_transition;
6666

6767
static int async_error;
6868

69+
/**
70+
* pm_hibernate_is_recovering - if recovering from hibernate due to error.
71+
*
72+
* Used to query if dev_pm_ops.thaw() is called for normal hibernation case or
73+
* recovering from some error.
74+
*
75+
* Return: true for error case, false for normal case.
76+
*/
77+
bool pm_hibernate_is_recovering(void)
78+
{
79+
return pm_transition.event == PM_EVENT_RECOVER;
80+
}
81+
EXPORT_SYMBOL_GPL(pm_hibernate_is_recovering);
82+
6983
static const char *pm_verb(int event)
7084
{
7185
switch (event) {

include/linux/suspend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ int is_hibernate_resume_dev(dev_t dev);
483483
static inline int is_hibernate_resume_dev(dev_t dev) { return 0; }
484484
#endif
485485

486+
bool pm_hibernate_is_recovering(void);
487+
486488
/* Hibernation and suspend events */
487489
#define PM_HIBERNATION_PREPARE 0x0001 /* Going to hibernate */
488490
#define PM_POST_HIBERNATION 0x0002 /* Hibernation finished */

0 commit comments

Comments
 (0)