From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpbguseast3.qq.com (smtpbguseast3.qq.com [54.243.244.52]) (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 E1F023C0621 for ; Wed, 29 Jul 2026 07:12:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.243.244.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785309168; cv=none; b=LcMaZcNr5D1GaL9ixHXVUp0E8FSaKh2VSZFnY6oBBicSgTotsCFSAKwhLc792eB9sf4GQ0QTC+zRCxPs/aQDvcv3yqR9Ah68ujhHGeWxItrPQkrXt9+jc8WSvj8Ju3apA0w14gjooyZ+RVfRriIeEm2m/38Q7D2lHdmTbh0P/3g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785309168; c=relaxed/simple; bh=0mwRk7GLVROlgRMPs5q2Igv7V8qKoyti5DUfIC/gP2c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ljmnkTXQ4rBfNauiRiEoRY41aU2F+H3Q0CgqNF47g0rp/gDtE+Z3LAvW62TeFVZPq6csZZbeSPL0MvMHLCtpKdDWiDa1rmYgDvFF7DL1vnjLM0wJYp5D/PAsqFeX7oSPXKwtP3rkP7SqAWAMldM1QBS225Ii4fZq2KLoqp+HTaY= 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=ToLSlfc7; arc=none smtp.client-ip=54.243.244.52 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="ToLSlfc7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1785309109; bh=JH1QDDx9o4boh27DWmqYCkbwbUyXJy/qdQiBxn++36c=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=ToLSlfc7nmgFgb2LzggQpMWPNXOpwcUJMK1VFko5xRxEFAR9mpzCTK19oNb2HY+5A lhAJREbUAR3Eb5AGxcgrZHUdXurE1NI2oM27EDubTVf/tsaKzwiSEhZ9gGUSmrNYtV QNh4oZ3rsinnaxQCsEQE3JW5YSp2pE9I5IsJLoEg= X-QQ-mid: zesmtpgz6t1785309095t97444c05 X-QQ-Originating-IP: F7xhpMI9oRzjaxfbDCiGGyerJ9Su+L/Hsf9QNyfpLtM= Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 29 Jul 2026 15:11:33 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 1664637546155480196 EX-QQ-RecipientCnt: 15 From: Haowen Tu To: laurent.pinchart@ideasonboard.com, rafael@kernel.org Cc: gregkh@linuxfoundation.org, hansg@kernel.org, kernel@uniontech.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, tuhaowen@uniontech.com Subject: [PATCH v4 1/4] PM: hibernate: clear in_suspend before freeing the snapshot Date: Wed, 29 Jul 2026 15:11:20 +0800 Message-Id: <4fafe6c2c7bc99e8b4e5042eae19ad9587f99cc1.1785226280.git.tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: <20260723084633.GE648629@killaraus.ideasonboard.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: zesmtpgz:uniontech.com:qybglogicsvrsz:qybglogicsvrsz3b-0 X-QQ-XMAILINFO: OTUHZG7Ulf3mFn1GNuXTk0/ybkFpWVbaXpzQJD6fqBlxNwa9yPQxxFqF vmd2nkdtRbvWC6zEJFGKgVxWhxkLEKW0YvNkvpFyVG/zt6nryOHJV8ZCEa9WomBVxjYQr6K FzOk1gEVbi1/eTWEatREAPUKS/XihGXWNOz30u9NHQITQ+1nZ2sLwq0CyJEfmVU3exz69Po ZeC7CkRTc8SjevZjJsbftozZwpTYYJQoniQZcWk20HqQIJYj4Zu0gnMoQP+IA2tiKds4yTz oQkLxSl0N5voFABzuog09qz96CNW7KHwElkn8/UhAHji5OZMFhyJfk2G9s5JABY/bx7HJv/ zfPv5uCEhbQYoQ88PqfR7oQjz2ZkeRn9jDZgWBxL8ErPOpnHn5xcMHzlfT7R+Gt7lIRusag XhbND0KNWXAlmQ3FL3imT7psDhDSLQ6wR2P2TkmFUN/Ya/ZIhMv7XcE+1wFSnrth75auNeN 9myh+3lKsYbchrxD2svHF2NzF80jc7gtRtRg990FbfIYM0HgTSF7TQEEMFq2UtsWBIKXcim oflkcF56AcOiWc69W0EPoCVJ3INzo1QRozOsmUXLANcMI4F/OkjRCp25khfCUPdduphN84r T7X8a4s2Jzu6eMUPMhMrrCiosejYfemp5cyKeId3KS2sqUzYMde91oaA0SDKjdrtRl083+L Z7j7KmmEAYlAwORbe8g8sq62z1oIOcIW7AUgXm73oj9N0TG9pEqfvuJeIcyQvW/n5uFrVbv 7f6qJvKY3hmZHrb9RPABmlS07lXjNYXQtCb0tZjXsorT7xQwbKNiXAkDhVnGsyF5Xak1Gef QmIrKUU94aphK05CkGvQhDqB8XzHQjBnne/niMLjtVuUILDfNXGMmKSxWP3QxiZ+DgDXC6x n4UzIPpinP+T5sR4LvehS7ftSFG7OKvqiZ8vwx9R3tKu3k+3nHqZouPXDf3GTm2UAITW3Xp ro47EYrkDKnNSUjuDt8J+cRrwCQKKPPlIM03M7v0lNUs3XZPCv3FQpcUQ8HKn1SWVoL7Aks +jXgPQd13TFNKmCWsAchoywCmajSa52D2CGe5GmbYE2F5VgVDbIeK3ExzqgvVeNT56bfCOA w== X-QQ-XMRINFO: OD9hHCdaPRBwH5bRRRw8tsiH4UAatJqXfg== 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. Acked-by: Rafael J. Wysocki (Intel) Signed-off-by: Haowen Tu --- 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