浏览代码

PM: Fix async resume following suspend failure

The PM core doesn't handle suspend failures correctly when it comes to
asynchronously suspended devices.  These devices are moved onto the
dpm_suspended_list as soon as the corresponding async thread is
started up, and they remain on the list even if they fail to suspend
or the sleep transition is cancelled before they get suspended.  As a
result, when the PM core unwinds the transition, it tries to resume
the devices even though they were never suspended.

This patch (as1474) fixes the problem by adding a new "is_suspended"
flag to dev_pm_info.  Devices are resumed only if the flag is set.

[rjw:
 * Moved the dev->power.is_suspended check into device_resume(),
   because we need to complete dev->power.completion and clear
   dev->power.is_prepared too for devices whose
   dev->power.is_suspended flags are unset.
 * Fixed __device_suspend() to avoid setting dev->power.is_suspended
   if async_error is different from zero.]

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: stable@kernel.org
Alan Stern 14 年之前
父节点
当前提交
6d0e0e84f6
共有 2 个文件被更改,包括 13 次插入2 次删除
  1. 12 2
      drivers/base/power/main.c
  2. 1 0
      include/linux/pm.h

+ 12 - 2
drivers/base/power/main.c

@@ -58,6 +58,7 @@ static int async_error;
 void device_pm_init(struct device *dev)
 void device_pm_init(struct device *dev)
 {
 {
 	dev->power.is_prepared = false;
 	dev->power.is_prepared = false;
+	dev->power.is_suspended = false;
 	init_completion(&dev->power.completion);
 	init_completion(&dev->power.completion);
 	complete_all(&dev->power.completion);
 	complete_all(&dev->power.completion);
 	dev->power.wakeup = NULL;
 	dev->power.wakeup = NULL;
@@ -517,6 +518,9 @@ static int device_resume(struct device *dev, pm_message_t state, bool async)
 	 */
 	 */
 	dev->power.is_prepared = false;
 	dev->power.is_prepared = false;
 
 
+	if (!dev->power.is_suspended)
+		goto Unlock;
+
 	if (dev->pwr_domain) {
 	if (dev->pwr_domain) {
 		pm_dev_dbg(dev, state, "power domain ");
 		pm_dev_dbg(dev, state, "power domain ");
 		error = pm_op(dev, &dev->pwr_domain->ops, state);
 		error = pm_op(dev, &dev->pwr_domain->ops, state);
@@ -552,6 +556,9 @@ static int device_resume(struct device *dev, pm_message_t state, bool async)
 	}
 	}
 
 
  End:
  End:
+	dev->power.is_suspended = false;
+
+ Unlock:
 	device_unlock(dev);
 	device_unlock(dev);
 	complete_all(&dev->power.completion);
 	complete_all(&dev->power.completion);
 
 
@@ -839,11 +846,11 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
 	device_lock(dev);
 	device_lock(dev);
 
 
 	if (async_error)
 	if (async_error)
-		goto End;
+		goto Unlock;
 
 
 	if (pm_wakeup_pending()) {
 	if (pm_wakeup_pending()) {
 		async_error = -EBUSY;
 		async_error = -EBUSY;
-		goto End;
+		goto Unlock;
 	}
 	}
 
 
 	if (dev->pwr_domain) {
 	if (dev->pwr_domain) {
@@ -881,6 +888,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
 	}
 	}
 
 
  End:
  End:
+	dev->power.is_suspended = !error;
+
+ Unlock:
 	device_unlock(dev);
 	device_unlock(dev);
 	complete_all(&dev->power.completion);
 	complete_all(&dev->power.completion);
 
 

+ 1 - 0
include/linux/pm.h

@@ -426,6 +426,7 @@ struct dev_pm_info {
 	unsigned int		can_wakeup:1;
 	unsigned int		can_wakeup:1;
 	unsigned int		async_suspend:1;
 	unsigned int		async_suspend:1;
 	bool			is_prepared:1;	/* Owned by the PM core */
 	bool			is_prepared:1;	/* Owned by the PM core */
+	bool			is_suspended:1;	/* Ditto */
 	spinlock_t		lock;
 	spinlock_t		lock;
 #ifdef CONFIG_PM_SLEEP
 #ifdef CONFIG_PM_SLEEP
 	struct list_head	entry;
 	struct list_head	entry;