From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpbg150.qq.com (smtpbg150.qq.com [18.132.163.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 431F228642B for ; Thu, 18 Jun 2026 01:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.132.163.193 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781746367; cv=none; b=qwtCT2iYiw3bPRGQyzp3k4qt671g3sZ8S2OjmDIuT1rssSZiFjoLhnhahMDAovrGrT+gIfInHjl8fmVg2XHNrAnpJSyghmcYsFvtZv7+pJ2nu5j4D5pXFfa4nW7o++SIxxlbEHUatoPvKndq35DcCL2eTM4iG9rIpbD5hMqK9js= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781746367; c=relaxed/simple; bh=TAIARPIajkOITGDbzSdoHBoCTTaPL3l2Xbtr82qtBKQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EO0COI9nQNaszbkcoM5ffWBxMIVfqlTfducl2ZEr/9ucceMWe5VMRUdu8lKy+2UXv2jMPtFkGHeOh/NRWw8/EyRUCH3tiGjvj45pzT2+5Vx2gkhyNjvemFB1sVPu6m6nba+Gc36L0DDR5vJSt/VqTrlQgc09/XBGLy8KvIwPydE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=dLngijdd; arc=none smtp.client-ip=18.132.163.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="dLngijdd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1781746323; bh=hfITmRqopvF8VmHdbL2kohw7TYEzFUvuc8O9lZccWZs=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=dLngijddGs63zE9F+q5M8Lofo+2fH5zWUedXui5KHebfSfDvSCQd8faQmL364XUlZ BTeaK2useAaLXAaC/sBAE7XQ22oreiLlAKuL+sv/4UUmopt1/bfbp5e/A+QrAuEkb2 jPbivTtzHNSR6Z0ankhN2P1EuDVO5zeeQ1uWuFyc= X-QQ-mid: esmtpsz10t1781746309t53ccef32 X-QQ-Originating-IP: llpGkfY8lgptXbhHPfjBEmBbKy49yDRwyfIoAWzQe7o= Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 18 Jun 2026 09:31:43 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 8223294922707337741 EX-QQ-RecipientCnt: 15 From: Haowen Tu 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 Message-Id: <20260618013133.1047270-2-tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260618013133.1047270-1-tuhaowen@uniontech.com> References: <20260602032413.1540166-1-tuhaowen@uniontech.com> <20260618013133.1047270-1-tuhaowen@uniontech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: esmtpsz:uniontech.com:qybglogicsvrsz:qybglogicsvrsz3b-0 X-QQ-XMAILINFO: M12MFmiBLnnlztpOmA1copk2dppxOc73q4qekDMnvE8/z9aWoY6/qT1O MobbXzGlyfV78kRSX4LmBIYcFZ5jCi6uMZDJO+85rcS9pQrJi6k7UbDKArCy6JyJFtLF7SF +VTQo36LHgqWJMyRQ30cqeacKY4OuJvneVGxmXTtfnp4WWHuhzj488Eo/VufgAYYaGLaxQX 4WTnlV98LCcK2JKLpHenBbFx6dOJqzSIM/H08t/HCu7PpzKh/qxZspRq6Zf8zkj1zkNXvXo jPzaUP2rKRiyOhP8GPcKX0OSJugLg8VEyW7dcpSpNJahFCABoCVzQTHZLZCyP29T9vFWiB3 fUV/AR33tmWOtgfSsuaLhq5U/coU4ZedOtxzfFMvtr8C9UDYYLctMrEihDrSWGxjfEYN8DW grY1eG/E8qbGvDfBgOxeqyoRjP9FPlss6newvxRDi7o/m/1p6EteND+T5KNZjhqPAyiptKk hARgOn2wvcgOe1fMYYfsuCStenArUnF9Xz1M2jKNqS+TZEx42sNF7mTo3IJWEpWk0g8wGQS 5qYV72bB+HVtYrYepeEsmZmZ6CuMKfZPtBgPf8F7QGzdSxRMMmw+DFmjCYxEI+Z/SZqRP8u EIJujBt7swnUzD1X3gGWiAIx4WbERScHKns9xql3hyIe7uAysN1BXiljeqpbXKJTZ/zPmwC IzmhW2OWHiKde7SQGx0EgIzHnqReQp6kQhqN6oHNpbYhg7bcldFlU43WlFRm4T/jPTbDvzP kRoe1GSHzn0EB37Sp8lWGohkednSo3bs1G4BbmU0UVP/kCCd+NnViPGFUlwLET4RU4NYJkR CM8PTK7uNaTcIb0RqHKuI3ozl+AdC3s9ViCwcWQU1nByazxwrD1uXUqbjVJzZv8dHSZl5fm GaTYQrQVc9lFs1tRNw0IGpQJVA9Ap9m6wD9XL/J7+3VRvVBZ1OJ5LbQLuqqAKb7sb0TevZN GEpEaAAc7Io3dlqFp74gvp6mI1QKbpvvPr0Iar0i/mYf+un4Vv9sGmm1ILYAqY0aLv5OXOZ ZFP69NeJ3JpsHcpuZPcM4H0a7YHb+YtbD9DsN4xkyo8nrjN01UcwxfLYn4jLI= X-QQ-XMRINFO: OWPUhxQsoeAVwkVaQIEGSKwwgKCxK/fD5g== X-QQ-RECHKSPAM: 0 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 --- 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