Re: [PATCH v3 1/3] PM: hibernate: clear in_suspend before freeing the snapshot
From: Rafael J. Wysocki (Intel)
Date: Wed Jul 22 2026 - 12:04:53 EST
On Thu, Jun 18, 2026 at 3:32 AM Haowen Tu <tuhaowen@xxxxxxxxxxxxx> wrote:
>
> 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@xxxxxxxxxxxxx>
This is fine with me, so
Acked-by: Rafael J. Wysocki (Intel) <rafael@xxxxxxxxxx>
and please feel free to route it along with the media patch.
Alternatively, I can pick up the whole series if I get an ACK on the
media patch.
> ---
> 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