From: Haowen Tu <tuhaowen@uniontech.com>
To: rafael@kernel.org
Cc: tuhaowen@uniontech.com, gregkh@linuxfoundation.org,
hansg@kernel.org, kernel@uniontech.com,
laurent.pinchart@ideasonboard.com, lenb@kernel.org,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-pm@vger.kernel.org, linux-usb@vger.kernel.org,
mchehab@kernel.org, oneukum@suse.com, pavel@kernel.org,
stern@rowland.harvard.edu
Subject: [PATCH v3 1/3] PM: hibernate: clear in_suspend before freeing the snapshot
Date: Thu, 18 Jun 2026 09:31:31 +0800 [thread overview]
Message-ID: <20260618013133.1047270-2-tuhaowen@uniontech.com> (raw)
In-Reply-To: <20260618013133.1047270-1-tuhaowen@uniontech.com>
in_suspend indicates that a hibernation snapshot has been created and is
still available. Keep that state consistent with the lifetime of the
snapshot memory by clearing in_suspend before swsusp_free() releases it.
If image creation fails after in_suspend has been set,
hibernation_snapshot() releases the snapshot memory but currently leaves
in_suspend set. Preserve its value locally long enough to select the
appropriate device resume message, then clear it before releasing the
snapshot.
Also clear in_suspend before releasing the snapshot after swsusp_write()
returns.
Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
Changes in v3:
- Split this cleanup from the helper patch.
kernel/power/hibernate.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index af8d07bafe02..6d3e637c5a02 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -418,6 +418,7 @@ static void shrink_shmem_memory(void)
int hibernation_snapshot(int platform_mode)
{
pm_message_t msg;
+ bool snapshot_done;
int error;
pm_suspend_clear_flags();
@@ -474,15 +475,18 @@ int hibernation_snapshot(int platform_mode)
* returns here (1) after the image has been created or the
* image creation has failed and (2) after a successful restore.
*/
+ snapshot_done = in_suspend;
/* We may need to release the preallocated image pages here. */
- if (error || !in_suspend)
+ if (error || !snapshot_done) {
+ in_suspend = 0;
swsusp_free();
+ }
- msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
+ msg = snapshot_done ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
dpm_resume(msg);
- if (error || !in_suspend)
+ if (error || !snapshot_done)
pm_restore_gfp_mask();
console_resume_all();
@@ -865,6 +869,7 @@ int hibernate(void)
pm_pr_dbg("Writing hibernation image.\n");
error = swsusp_write(flags);
+ in_suspend = 0;
swsusp_free();
if (!error) {
if (hibernation_mode == HIBERNATION_TEST_RESUME)
@@ -872,7 +877,6 @@ int hibernate(void)
else
power_down();
}
- in_suspend = 0;
pm_restore_gfp_mask();
} else {
pm_pr_dbg("Hibernation image restored successfully.\n");
--
2.20.1
next prev parent reply other threads:[~2026-06-18 1:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260428080513.1833515-1-tuhaowen@uniontech.com>
2026-05-28 8:18 ` [PATCH v2 0/2] PM: hibernate: skip UVC resume after snapshot Haowen Tu
2026-05-28 8:18 ` [PATCH v2 1/2] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
2026-06-01 18:22 ` Rafael J. Wysocki
2026-06-02 3:24 ` Haowen Tu
2026-06-18 1:31 ` [PATCH v3 0/3] PM: hibernate: skip UVC streaming restart after snapshot Haowen Tu
2026-06-18 1:31 ` Haowen Tu [this message]
2026-06-18 1:31 ` [PATCH v3 2/3] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
2026-06-18 1:31 ` [PATCH v3 3/3] media: uvcvideo: skip streaming restart after hibernation snapshot Haowen Tu
2026-05-28 8:18 ` [PATCH v2 2/2] media: uvcvideo: skip resume " Haowen Tu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260618013133.1047270-2-tuhaowen@uniontech.com \
--to=tuhaowen@uniontech.com \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=kernel@uniontech.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=oneukum@suse.com \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox