From patchwork Fri Jul 1 21:13:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Stern X-Patchwork-Id: 938122 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 p61LGEiI026828 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 1 Jul 2011 21:16:35 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 p61LEprs022433; Fri, 1 Jul 2011 14:14:52 -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 p61LDpWO022345 for ; Fri, 1 Jul 2011 14:13:52 -0700 Received: (qmail 2197 invoked by uid 2102); 1 Jul 2011 17:13:51 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 1 Jul 2011 17:13:51 -0400 Date: Fri, 1 Jul 2011 17:13:51 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: "Rafael J. Wysocki" In-Reply-To: Message-ID: MIME-Version: 1.0 Received-SPF: pass (localhost is always allowed.) X-Spam-Status: No, hits=-5.507 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, PATCH_SUBJECT_OSDL 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] PM: prevent runtime_resume from racing with probe 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, 01 Jul 2011 21:16:35 +0000 (UTC) This patch (as1475) adds device_lock() and device_unlock() calls to the store methods for the power/control and power/autosuspend_delay_ms sysfs attribute files. We don't want badly timed writes to these files to cause runtime_resume callbacks to occur while a driver is being probed for a device. Signed-off-by: Alan Stern --- drivers/base/power/sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) Index: usb-3.0/drivers/base/power/sysfs.c =================================================================== --- usb-3.0.orig/drivers/base/power/sysfs.c +++ usb-3.0/drivers/base/power/sysfs.c @@ -116,12 +116,14 @@ static ssize_t control_store(struct devi cp = memchr(buf, '\n', n); if (cp) len = cp - buf; + device_lock(dev); if (len == sizeof ctrl_auto - 1 && strncmp(buf, ctrl_auto, len) == 0) pm_runtime_allow(dev); else if (len == sizeof ctrl_on - 1 && strncmp(buf, ctrl_on, len) == 0) pm_runtime_forbid(dev); else - return -EINVAL; + n = -EINVAL; + device_unlock(dev); return n; } @@ -205,7 +207,9 @@ static ssize_t autosuspend_delay_ms_stor if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay) return -EINVAL; + device_lock(dev); pm_runtime_set_autosuspend_delay(dev, delay); + device_unlock(dev); return n; }