Re: [PATCH v1] PM: hibernate: Avoid redundant resume_device assignment in resume_store()

From: Zihuan Zhang
Date: Thu Jul 03 2025 - 01:14:53 EST


Hi Rafael,

在 2025/7/3 02:51, Rafael J. Wysocki 写道:
On Fri, May 30, 2025 at 12:00 PM Zihuan Zhang <zhangzihuan@xxxxxxxxxx> wrote:
In resume_store(), if the device number written to /sys/power/resume
is the same as the current swsusp_resume_device, we can skip reassignment.
This avoids unnecessary locking and improves efficiency slightly.

Signed-off-by: Zihuan Zhang <zhangzihuan@xxxxxxxxxx>
---
kernel/power/hibernate.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 519fb09de5e0..504a1c2465ce 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -1291,6 +1291,9 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
if (error)
return error;

+ if (dev == swsusp_resume_device)
+ return n;
+
The main purpose of this function is to run software_resume(), not to
set swsusp_resume_device. You're breaking it with this change.
Thank you for the feedback.

You’re absolutely right — I misunderstood the primary role of resume_store() as being only to update swsusp_resume_device, and I overlooked that its main purpose is to trigger software_resume().

I’ll drop this patch accordingly. Thanks again for pointing this out.

sleep_flags = lock_system_sleep();
swsusp_resume_device = dev;
unlock_system_sleep(sleep_flags);
--
2.25.1

Best regards,
Zihuan Zhang