From patchwork Fri Jun 17 20:08:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Stern X-Patchwork-Id: 892432 Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5HKBj9M009175 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 17 Jun 2011 20:12:06 GMT Received: from daredevil.linux-foundation.org (localhost [127.0.0.1]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p5HK9D6C026245; Fri, 17 Jun 2011 13:09:41 -0700 Received: from iolanthe.rowland.org (iolanthe.rowland.org [192.131.102.54]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with SMTP id p5HK8MLw026142 for ; Fri, 17 Jun 2011 13:08:23 -0700 Received: (qmail 6186 invoked by uid 2102); 17 Jun 2011 16:08:22 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 17 Jun 2011 16:08:22 -0400 Date: Fri, 17 Jun 2011 16:08:22 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: "Rafael J. Wysocki" Message-ID: MIME-Version: 1.0 Received-SPF: pass (localhost is always allowed.) X-Spam-Status: No, hits=-3.999 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.21 Cc: Linux-pm mailing list Subject: [linux-pm] [PATCH 2/2] PM: fix async resume following suspend failure X-BeenThere: linux-pm@lists.linux-foundation.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux power management List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 17 Jun 2011 20:12:06 +0000 (UTC) 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. Signed-off-by: Alan Stern --- Rafael, you may want these two patches to go into the stable kernels. I'll leave that decision to you. drivers/base/power/main.c | 8 +++++--- include/linux/pm.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) Index: usb-3.0/include/linux/pm.h =================================================================== --- usb-3.0.orig/include/linux/pm.h +++ usb-3.0/include/linux/pm.h @@ -426,6 +426,7 @@ struct dev_pm_info { unsigned int can_wakeup:1; unsigned int async_suspend:1; bool is_prepared:1; /* Owned by the PM core */ + bool is_suspended:1; /* Ditto */ spinlock_t lock; #ifdef CONFIG_PM_SLEEP struct list_head entry; Index: usb-3.0/drivers/base/power/main.c =================================================================== --- usb-3.0.orig/drivers/base/power/main.c +++ usb-3.0/drivers/base/power/main.c @@ -57,7 +57,7 @@ static int async_error; */ void device_pm_init(struct device *dev) { - dev->power.is_prepared = false; + dev->power.is_prepared = dev->power.is_suspended = false; init_completion(&dev->power.completion); complete_all(&dev->power.completion); dev->power.wakeup = NULL; @@ -552,6 +552,7 @@ static int device_resume(struct device * } End: + dev->power.is_suspended = false; device_unlock(dev); complete_all(&dev->power.completion); @@ -596,7 +597,7 @@ void dpm_resume(pm_message_t state) list_for_each_entry(dev, &dpm_suspended_list, power.entry) { INIT_COMPLETION(dev->power.completion); - if (is_async(dev)) { + if (is_async(dev) && dev->power.is_suspended) { get_device(dev); async_schedule(async_resume, dev); } @@ -605,7 +606,7 @@ void dpm_resume(pm_message_t state) while (!list_empty(&dpm_suspended_list)) { dev = to_device(dpm_suspended_list.next); get_device(dev); - if (!is_async(dev)) { + if (!is_async(dev) && dev->power.is_suspended) { int error; mutex_unlock(&dpm_list_mtx); @@ -881,6 +882,7 @@ static int __device_suspend(struct devic } End: + dev->power.is_suspended = !error; device_unlock(dev); complete_all(&dev->power.completion);