PM: runtime: add might_sleep to PM runtime functions
authorColin Cross <ccross@android.com>
Wed, 10 Aug 2011 16:41:59 +0000 (11:41 -0500)
committerColin Cross <ccross@android.com>
Sat, 24 Sep 2011 03:08:51 +0000 (20:08 -0700)
The list of functions that can be called in atomic context is
non-intuitive (pm_runtime_put_sync can not, but
pm_runtime_put_sync_suspend can, if pm_runtime_irq_safe has
been called?).  The code is actively misleading - the entry
points all start with spin_lock_irqsave, suggesting they
are safe to call in atomic context, but may later
enable interrupts.

Add might_sleep_if to all the __pm_runtime_* entry points
to enforce correct usage.

Also add pm_runtime_put_sync_autosuspend to the list of
functions that can be called in atomic context.

Change-Id: Icac17a10d77c64d44bd2761a91a588dfd1d0c6f0
Signed-off-by: Colin Cross <ccross@android.com>
Documentation/power/runtime_pm.txt
drivers/base/power/runtime.c

index b24875b1ced5f04ff7caff5a6f99f89ebe3a32ff..22852b3cf49f7a6c9038b997e8eef06756a57834 100644 (file)
@@ -469,6 +469,7 @@ pm_runtime_autosuspend()
 pm_runtime_resume()
 pm_runtime_get_sync()
 pm_runtime_put_sync_suspend()
+pm_runtime_put_sync_autosuspend()
 
 5. Run-time PM Initialization, Device Probing and Removal
 
index 0d4587b15c5599372e7b9f917fcea636404bf8d9..577f4fd1648037592de188ce9dab16704ce4c620 100644 (file)
@@ -732,6 +732,8 @@ int __pm_runtime_idle(struct device *dev, int rpmflags)
        unsigned long flags;
        int retval;
 
+       might_sleep_if(!(rpmflags & RPM_ASYNC));
+
        if (rpmflags & RPM_GET_PUT) {
                if (!atomic_dec_and_test(&dev->power.usage_count))
                        return 0;
@@ -761,6 +763,8 @@ int __pm_runtime_suspend(struct device *dev, int rpmflags)
        unsigned long flags;
        int retval;
 
+       might_sleep_if(!(rpmflags & RPM_ASYNC) && !dev->power.irq_safe);
+
        if (rpmflags & RPM_GET_PUT) {
                if (!atomic_dec_and_test(&dev->power.usage_count))
                        return 0;
@@ -789,6 +793,8 @@ int __pm_runtime_resume(struct device *dev, int rpmflags)
        unsigned long flags;
        int retval;
 
+       might_sleep_if(!(rpmflags & RPM_ASYNC) && !dev->power.irq_safe);
+
        if (rpmflags & RPM_GET_PUT)
                atomic_inc(&dev->power.usage_count);
 
@@ -978,6 +984,7 @@ EXPORT_SYMBOL_GPL(pm_runtime_barrier);
  */
 void __pm_runtime_disable(struct device *dev, bool check_resume)
 {
+       might_sleep();
        spin_lock_irq(&dev->power.lock);
 
        if (dev->power.disable_depth > 0) {
@@ -1184,6 +1191,8 @@ void __pm_runtime_use_autosuspend(struct device *dev, bool use)
 {
        int old_delay, old_use;
 
+       might_sleep();
+
        spin_lock_irq(&dev->power.lock);
        old_delay = dev->power.autosuspend_delay;
        old_use = dev->power.use_autosuspend;