patch usb-fix-race-in-autosuspend-reschedule.patch added to gregkh-2.6 tree

<[email protected]>
Newsgroups gmane.linux.usb.devel
Message-ID <[email protected]>
This is a note to let you know that I've just added the patch titled

     Subject: USB: fix race in autosuspend reschedule

to my gregkh-2.6 tree.  Its filename is

     usb-fix-race-in-autosuspend-reschedule.patch

This tree can be found at 
    http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/


>From [email protected] Thu Oct 11 13:47:47 2007
From: Alan Stern <[email protected]>
Date: Thu, 11 Oct 2007 16:47:36 -0400 (EDT)
Subject: USB: fix race in autosuspend reschedule
To: Greg KH <[email protected]>
Cc: USB development list <[email protected]>
Message-ID: <[email protected]>


This patch (as1002) fixes a small race which can occur when a driver
expects usbcore to reschedule an autosuspend request.  If the request
arrives too late, it won't be rescheduled.  The patch adds an extra
argument to autosuspend_check(), indicating that a reschedule is
needed no matter how much time has elapsed.

It also tries to avoid letting asynchronous changes to the value of
jiffies cause a delay to become negative, by caching a local copy of
the current time.

Signed-off-by: Alan Stern <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 drivers/usb/core/driver.c |   32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -935,11 +935,11 @@ done:
 #ifdef	CONFIG_USB_SUSPEND
 
 /* Internal routine to check whether we may autosuspend a device. */
-static int autosuspend_check(struct usb_device *udev)
+static int autosuspend_check(struct usb_device *udev, int reschedule)
 {
 	int			i;
 	struct usb_interface	*intf;
-	unsigned long		suspend_time;
+	unsigned long		suspend_time, j;
 
 	/* For autosuspend, fail fast if anything is in use or autosuspend
 	 * is disabled.  Also fail if any interfaces require remote wakeup
@@ -981,20 +981,20 @@ static int autosuspend_check(struct usb_
 	}
 
 	/* If everything is okay but the device hasn't been idle for long
-	 * enough, queue a delayed autosuspend request.
+	 * enough, queue a delayed autosuspend request.  If the device
+	 * _has_ been idle for long enough and the reschedule flag is set,
+	 * likewise queue a delayed (1 second) autosuspend request.
 	 */
-	if (time_after(suspend_time, jiffies)) {
+	j = jiffies;
+	if (time_before(j, suspend_time))
+		reschedule = 1;
+	else
+		suspend_time = j + HZ;
+	if (reschedule) {
 		if (!timer_pending(&udev->autosuspend.timer)) {
-
-			/* The value of jiffies may change between the
-			 * time_after() comparison above and the subtraction
-			 * below.  That's okay; the system behaves sanely
-			 * when a timer is registered for the present moment
-			 * or for the past.
-			 */
 			queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
-				round_jiffies_relative(suspend_time - jiffies));
-			}
+				round_jiffies_relative(suspend_time - j));
+		}
 		return -EAGAIN;
 	}
 	return 0;
@@ -1002,7 +1002,7 @@ static int autosuspend_check(struct usb_
 
 #else
 
-static inline int autosuspend_check(struct usb_device *udev)
+static inline int autosuspend_check(struct usb_device *udev, int reschedule)
 {
 	return 0;
 }
@@ -1059,7 +1059,7 @@ static int usb_suspend_both(struct usb_d
 	udev->do_remote_wakeup = device_may_wakeup(&udev->dev);
 
 	if (udev->auto_pm) {
-		status = autosuspend_check(udev);
+		status = autosuspend_check(udev, 0);
 		if (status < 0)
 			goto done;
 	}
@@ -1085,7 +1085,7 @@ static int usb_suspend_both(struct usb_d
 
 		/* Try another autosuspend when the interfaces aren't busy */
 		if (udev->auto_pm)
-			autosuspend_check(udev);
+			autosuspend_check(udev, status == -EBUSY);
 
 	/* If the suspend succeeded then prevent any more URB submissions,
 	 * flush any outstanding URBs, and propagate the suspend up the tree.


Patches currently in gregkh-2.6 which might be from [email protected] are

driver/sysfs-remove-first-pass-at-shadow-directory-support.patch
driver/sysfs-fix-i_mutex-locking-in-sysfs_get_dentry.patch
driver/sysfs-in-sysfs_lookup-don-t-open-code-sysfs_find_dirent.patch
driver/sysfs-cosmetic-changes-in-sysfs_lookup.patch
driver/sysfs-make-sysfs_add-remove_one-call-link-unlink_sibling-implictly.patch
driver/sysfs-make-sysfs_add_one-automatically-check-for-duplicate-entry.patch
driver/sysfs-make-sysfs_addrm_finish-return-void.patch
driver/sysfs-simplify-sysfs_rename_dir.patch
driver/sysfs-introduce-sysfs_rename_mutex.patch
driver/sysfs-clean-up-header-files.patch
driver/sysfs-make-sysfs_mount-static.patch
driver/sysfs-remove-s_dentry.patch
driver/sysfs-remove-sysfs_instantiate.patch
driver/sysfs-rewrite-rename-in-terms-of-sysfs-dirents.patch
driver/sysfs-move-all-of-inode-initialization-into-sysfs_init_inode.patch
driver/sysfs-rewrite-sysfs_drop_dentry.patch
driver/sysfs-rewrite-sysfs_move_dir-in-terms-of-sysfs-dirents.patch
driver/sysfs-simplify-readdir.patch
driver/sysfs-simply-sysfs_get_dentry.patch
driver/sysfs-use-kill_anon_super.patch
driver/sysfs-fix-comments-of-sysfs_add-remove_one.patch
driver/sysfs-fix-sysfs_chmod_file-such-that-it-updates-sd-s_mode-too.patch
driver/sysfs-implement-sysfs_open_dirent.patch
driver/sysfs-kill-sysfs_update_file.patch
driver/sysfs-kill-unnecessary-null-pointer-check-in-sysfs_release.patch
driver/sysfs-kill-unnecessary-sysfs_get-in-open-paths.patch
driver/sysfs-make-bin-attr-open-get-active-reference-of-parent-too.patch
driver/sysfs-make-s_elem-an-anonymous-union.patch
driver/sysfs-make-sysfs_root-a-regular-directory-dirent.patch
driver/sysfs-move-sysfs-file-poll-implementation-to-sysfs_open_dirent.patch
driver/sysfs-move-sysfs_dirent-s_children-into-sysfs_dirent-s_dir.patch
driver/sysfs-open-code-sysfs_attach_dentry.patch
driver/sysfs-reposition-sysfs_dirent-s_mode.patch
driver/pm-acquire-device-locks-prior-to-suspending.patch
driver/pm-merge-device-power-management-source-files.patch
driver/sysfs-add-copyrights.patch
usb/usb-add-ep-enable.patch
usb/usb-avoid-the-donelist-after-an-error-in-ohci-hcd.patch
usb/usb-add-direction-bit-to-urb-transfer_flags.patch
usb/usb-add-urb-ep.patch
usb/usb-address-0-handling-during-device-initialization.patch
usb/usb-avoid-urb-pipe-in-usbfs.patch
usb/usb-avoid-urb-pipe-in-usbmon.patch
usb/usb-avoid-using-urb-pipe-in-usbcore.patch
usb/usb-cleanup-for-previous-patches.patch
usb/usb-gadget-file-storage-gadget-cleanups.patch
usb/usb-separate-out-endpoint-queue-management-and-dma-mapping-routines.patch
usb/usb-update-spinlock-usage-for-root-hub-urbs.patch
usb/usb-fix-mistake-in-usb_hcd_giveback_urb.patch
usb/usb-less-restrictive-command-checking-in-g-file-storage.patch
usb/usb-reorganize-urb-status-use-in-dummy-hcd.patch
usb/usb-reorganize-urb-status-use-in-ehci-hcd.patch
usb/usb-reorganize-urb-status-use-in-ohci-hcd.patch
usb/usb-reorganize-urb-status-use-in-r8a66597-hcd.patch
usb/usb-reorganize-urb-status-use-in-sl811-hcd.patch
usb/usb-reorganize-urb-status-use-in-usbmon.patch
usb/usb-eliminate-urb-status-usage.patch
usb/usb-cleanups-for-g_file_storage.patch
usb/usb-don-t-touch-sysfs-stuff-when-altsetting-is-unchanged.patch
usb/usb-make-hcds-responsible-for-managing-endpoint-queues.patch
usb/usb-get-rid-of-urb-lock.patch
usb/usb-remove-traces-of-urb-status-from-usbcore.patch
usb/usb-usbmon-doc-update-mention-new-wildcard-bus.patch
usb/usbmon-update-pipe-removal-to-suit-my-taste.patch
usb/usb-break-apart-flush_endpoint-and-disable_endpoint.patch
usb/usb-fix-location-of-statement-label-in-dummy-hcd.patch
usb/usb-flush-outstanding-urbs-when-suspending.patch
usb/usb-get-rid-of-annoying-endpoint-release-message.patch
usb/usb-move-decision-to-ignore-freeze-events.patch
usb/usb-remove-unnecessary-tests-in-isp116x-and-sl811.patch
usb/usb-add-urb-unlinked-field.patch
usb/usb-centralize-eremoteio-handling.patch
usb/usb-driver-for-ch341-usb-serial-adaptor.patch
usb/usb-minor-fixes-for-r8a66597-driver.patch
usb/usb-remove-iso-status-value-in-uhci-hcd.patch
usb/usb-fix-double-frees-in-error-code-paths-of-ipaq-driver.patch
usb/usb-fix-limited_power-setting-mistake-in-hub.c.patch
usb/usb-don-t-propagate-freeze-or-prethaw-suspends.patch
usb/usb-remove-usb_quirk_no_autosuspend.patch
usb/usb-unusual_devs-modification-for-nikon-d200.patch
usb/usb-unusual_devs-update-for-nokia-6131.patch
usb/usb-unusual_devs-entry-for-nikon-dsc-d2xs.patch
usb/usb-storage-always-set-the-allow_restart-flag.patch
usb/usb-mutual-exclusion-for-ehci-init-and-port-resets.patch
usb/usb-documentation-for-usb-power-management.patch
usb/usb-serial-core-should-respect-driver-requirements.patch
usb/usb-skip-autosuspended-devices-during-system-resume.patch
usb/usb-fix-race-in-autosuspend-reschedule.patch

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.