PM / Sleep: Move disabling of usermode helpers to the freezer
authorRafael J. Wysocki <rjw@sisk.pl>
Wed, 28 Mar 2012 21:30:21 +0000 (23:30 +0200)
committerRafael J. Wysocki <rjw@sisk.pl>
Wed, 28 Mar 2012 21:30:21 +0000 (23:30 +0200)
The core suspend/hibernation code calls usermodehelper_disable() to
avoid race conditions between the freezer and the starting of
usermode helpers and each code path has to do that on its own.
However, it is always called right before freeze_processes()
and usermodehelper_enable() is always called right after
thaw_processes().  For this reason, to avoid code duplication and
to make the connection between usermodehelper_disable() and the
freezer more visible, make freeze_processes() call it and remove the
direct usermodehelper_disable() and usermodehelper_enable() calls
from all suspend/hibernation code paths.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org
kernel/power/hibernate.c
kernel/power/process.c
kernel/power/suspend.c
kernel/power/user.c

index 639ff6e4ae9eb09f968564c32ad15e31c9124899..e09dfbfeecee43ca7fff59c327f213f9605ef0f4 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/string.h>
 #include <linux/device.h>
 #include <linux/async.h>
-#include <linux/kmod.h>
 #include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/mount.h>
@@ -620,10 +619,6 @@ int hibernate(void)
        sys_sync();
        printk("done.\n");
 
-       error = usermodehelper_disable();
-       if (error)
-               goto Exit;
-
        error = freeze_processes();
        if (error)
                goto Free_bitmaps;
@@ -660,7 +655,6 @@ int hibernate(void)
        freezer_test_done = false;
 
  Free_bitmaps:
-       usermodehelper_enable();
        free_basic_memory_bitmaps();
  Exit:
        pm_notifier_call_chain(PM_POST_HIBERNATION);
@@ -780,10 +774,6 @@ static int software_resume(void)
        if (error)
                goto close_finish;
 
-       error = usermodehelper_disable();
-       if (error)
-               goto close_finish;
-
        pr_debug("PM: Preparing processes for restore.\n");
        error = freeze_processes();
        if (error) {
@@ -802,7 +792,6 @@ static int software_resume(void)
        swsusp_free();
        thaw_processes();
  Done:
-       usermodehelper_enable();
        free_basic_memory_bitmaps();
  Finish:
        pm_notifier_call_chain(PM_POST_RESTORE);
index 0d2aeb2261082f52d4ead619f352f03c03c35001..56eaac7e88abe3f8bf56ad162bd2dc6e62f56460 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/freezer.h>
 #include <linux/delay.h>
 #include <linux/workqueue.h>
+#include <linux/kmod.h>
 
 /* 
  * Timeout for stopping processes
@@ -122,6 +123,10 @@ int freeze_processes(void)
 {
        int error;
 
+       error = usermodehelper_disable();
+       if (error)
+               return error;
+
        if (!pm_freezing)
                atomic_inc(&system_freezing_cnt);
 
@@ -187,6 +192,8 @@ void thaw_processes(void)
        } while_each_thread(g, p);
        read_unlock(&tasklist_lock);
 
+       usermodehelper_enable();
+
        schedule();
        printk("done.\n");
 }
index 88e5c967370d31e359cbd06f23914735c11f15b2..396d262b8fd01381a99de04d2d310be787b37565 100644 (file)
@@ -12,7 +12,6 @@
 #include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/init.h>
-#include <linux/kmod.h>
 #include <linux/console.h>
 #include <linux/cpu.h>
 #include <linux/syscalls.h>
@@ -102,17 +101,12 @@ static int suspend_prepare(void)
        if (error)
                goto Finish;
 
-       error = usermodehelper_disable();
-       if (error)
-               goto Finish;
-
        error = suspend_freeze_processes();
        if (!error)
                return 0;
 
        suspend_stats.failed_freeze++;
        dpm_save_failed_step(SUSPEND_FREEZE);
-       usermodehelper_enable();
  Finish:
        pm_notifier_call_chain(PM_POST_SUSPEND);
        pm_restore_console();
@@ -259,7 +253,6 @@ int suspend_devices_and_enter(suspend_state_t state)
 static void suspend_finish(void)
 {
        suspend_thaw_processes();
-       usermodehelper_enable();
        pm_notifier_call_chain(PM_POST_SUSPEND);
        pm_restore_console();
 }
index 33c4329205af0e88da9e80ee98e9ff0e1259bf7d..91b0fd021a95d08eef106b3e0b86a41e3a135055 100644 (file)
@@ -12,7 +12,6 @@
 #include <linux/suspend.h>
 #include <linux/syscalls.h>
 #include <linux/reboot.h>
-#include <linux/kmod.h>
 #include <linux/string.h>
 #include <linux/device.h>
 #include <linux/miscdevice.h>
@@ -222,14 +221,8 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
                sys_sync();
                printk("done.\n");
 
-               error = usermodehelper_disable();
-               if (error)
-                       break;
-
                error = freeze_processes();
-               if (error)
-                       usermodehelper_enable();
-               else
+               if (!error)
                        data->frozen = 1;
                break;
 
@@ -238,7 +231,6 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
                        break;
                pm_restore_gfp_mask();
                thaw_processes();
-               usermodehelper_enable();
                data->frozen = 0;
                break;