PM / sleep: Make lock/unlock_system_sleep() available to kernel modules
authorBart Van Assche <bart.vanassche@wdc.com>
Fri, 5 Jan 2018 17:19:08 +0000 (09:19 -0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 10 Jan 2018 00:07:46 +0000 (01:07 +0100)
Since pm_mutex is not exported using lock/unlock_system_sleep() from
inside a kernel module causes a "pm_mutex undefined" linker error.
Hence move lock/unlock_system_sleep() into kernel/power/main.c and
export these.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
include/linux/suspend.h
kernel/power/main.c

index d60b0f5c38d504e52a2c1c2726476def808595c7..cc22a24516d699582a639329a99df51eb5bb2fb4 100644 (file)
@@ -443,32 +443,8 @@ extern bool pm_save_wakeup_count(unsigned int count);
 extern void pm_wakep_autosleep_enabled(bool set);
 extern void pm_print_active_wakeup_sources(void);
 
-static inline void lock_system_sleep(void)
-{
-       current->flags |= PF_FREEZER_SKIP;
-       mutex_lock(&pm_mutex);
-}
-
-static inline void unlock_system_sleep(void)
-{
-       /*
-        * Don't use freezer_count() because we don't want the call to
-        * try_to_freeze() here.
-        *
-        * Reason:
-        * Fundamentally, we just don't need it, because freezing condition
-        * doesn't come into effect until we release the pm_mutex lock,
-        * since the freezer always works with pm_mutex held.
-        *
-        * More importantly, in the case of hibernation,
-        * unlock_system_sleep() gets called in snapshot_read() and
-        * snapshot_write() when the freezing condition is still in effect.
-        * Which means, if we use try_to_freeze() here, it would make them
-        * enter the refrigerator, thus causing hibernation to lockup.
-        */
-       current->flags &= ~PF_FREEZER_SKIP;
-       mutex_unlock(&pm_mutex);
-}
+extern void lock_system_sleep(void);
+extern void unlock_system_sleep(void);
 
 #else /* !CONFIG_PM_SLEEP */
 
index 3a2ca9066583fad36e3b91fe99515058d453a62e..705c2366dafe19c13f011885df1e2ae93c2687e7 100644 (file)
@@ -22,6 +22,35 @@ DEFINE_MUTEX(pm_mutex);
 
 #ifdef CONFIG_PM_SLEEP
 
+void lock_system_sleep(void)
+{
+       current->flags |= PF_FREEZER_SKIP;
+       mutex_lock(&pm_mutex);
+}
+EXPORT_SYMBOL_GPL(lock_system_sleep);
+
+void unlock_system_sleep(void)
+{
+       /*
+        * Don't use freezer_count() because we don't want the call to
+        * try_to_freeze() here.
+        *
+        * Reason:
+        * Fundamentally, we just don't need it, because freezing condition
+        * doesn't come into effect until we release the pm_mutex lock,
+        * since the freezer always works with pm_mutex held.
+        *
+        * More importantly, in the case of hibernation,
+        * unlock_system_sleep() gets called in snapshot_read() and
+        * snapshot_write() when the freezing condition is still in effect.
+        * Which means, if we use try_to_freeze() here, it would make them
+        * enter the refrigerator, thus causing hibernation to lockup.
+        */
+       current->flags &= ~PF_FREEZER_SKIP;
+       mutex_unlock(&pm_mutex);
+}
+EXPORT_SYMBOL_GPL(unlock_system_sleep);
+
 /* Routines for PM-transition notifications */
 
 static BLOCKING_NOTIFIER_HEAD(pm_chain_head);