PM: hibernate: Turn snapshot_test into global variable
authorChen Yu <yu.c.chen@intel.com>
Fri, 14 Apr 2023 12:10:26 +0000 (20:10 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 27 Apr 2023 17:00:28 +0000 (19:00 +0200)
There is need to check snapshot_test and open block device
in different mode, so as to avoid the race condition.

No functional changes intended.

Suggested-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/hibernate.c
kernel/power/power.h

index 793c55a2becba62705e7237e3de17c3d19b6f611..aa551b093c3f616bd72f966f68c7d78b3b44d9d3 100644 (file)
@@ -64,6 +64,7 @@ enum {
 static int hibernation_mode = HIBERNATION_SHUTDOWN;
 
 bool freezer_test_done;
+bool snapshot_test;
 
 static const struct platform_hibernation_ops *hibernation_ops;
 
@@ -716,7 +717,6 @@ static int load_image_and_restore(void)
  */
 int hibernate(void)
 {
-       bool snapshot_test = false;
        unsigned int sleep_flags;
        int error;
 
@@ -744,6 +744,9 @@ int hibernate(void)
        if (error)
                goto Exit;
 
+       /* protected by system_transition_mutex */
+       snapshot_test = false;
+
        lock_device_hotplug();
        /* Allocate memory management structures */
        error = create_basic_memory_bitmaps();
@@ -940,6 +943,8 @@ static int software_resume(void)
         */
        mutex_lock_nested(&system_transition_mutex, SINGLE_DEPTH_NESTING);
 
+       snapshot_test = false;
+
        if (swsusp_resume_device)
                goto Check_image;
 
index b4f4339432096148567a6605cca0d99d4dcabe87..b83c8d5e188dec950ce762356c840a094136d860 100644 (file)
@@ -59,6 +59,7 @@ asmlinkage int swsusp_save(void);
 
 /* kernel/power/hibernate.c */
 extern bool freezer_test_done;
+extern bool snapshot_test;
 
 extern int hibernation_snapshot(int platform_mode);
 extern int hibernation_restore(int platform_mode);