Discussion:
[PATCH 1/2] USB: implement "soft" unbinding
(too old to reply)
Alan Stern
2008-05-08 15:54:37 UTC
Permalink
This patch (as1091) changes the way usbcore handles interface
unbinding. If the interface's driver supports "soft" unbinding (a new
flag in the driver structure) then in-flight URBs are not cancelled
and endpoints are not disabled. Instead the driver is allowed to
continue communicating with the device (although of course it should
stop before its disconnect routine returns).

The purpose of this change is to allow drivers to do a clean shutdown
when they get unbound from a device that is still plugged in. Killing
all the URBs and disabling the endpoints before calling the driver's
disconnect method doesn't give the driver any control over what
happens, and it can leave devices in indeterminate states. For
example, when usb-storage unbinds it doesn't want to stop while in the
middle of transmitting a SCSI command.

The soft_unbind flag is added because in the past, a number of drivers
have experienced problems related to ongoing I/O after their disconnect
routine returned. Hence "soft" unbinding is made available only to
drivers that claim to support it.

The patch also replaces "interface_to_usbdev(intf)" with "udev" in a
couple of places, a minor simplification.

Signed-off-by: Alan Stern <stern-nwvwT67g6+6dFdvTe/***@public.gmane.org>

---

Index: usb-2.6/include/linux/usb.h
===================================================================
--- usb-2.6.orig/include/linux/usb.h
+++ usb-2.6/include/linux/usb.h
@@ -975,6 +975,8 @@ struct usbdrv_wrap {
* added to this driver by preventing the sysfs file from being created.
* @supports_autosuspend: if set to 0, the USB core will not allow autosuspend
* for interfaces bound to this driver.
+ * @soft_unbind: if set to 1, the USB core will not kill URBs and disable
+ * endpoints before calling the driver's disconnect method.
*
* USB interface drivers must provide a name, probe() and disconnect()
* methods, and an id_table. Other driver fields are optional.
@@ -1015,6 +1017,7 @@ struct usb_driver {
struct usbdrv_wrap drvwrap;
unsigned int no_dynamic_id:1;
unsigned int supports_autosuspend:1;
+ unsigned int soft_unbind:1;
};
#define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver)

Index: usb-2.6/drivers/usb/core/driver.c
===================================================================
--- usb-2.6.orig/drivers/usb/core/driver.c
+++ usb-2.6/drivers/usb/core/driver.c
@@ -257,15 +257,16 @@ static int usb_unbind_interface(struct d
udev = interface_to_usbdev(intf);
error = usb_autoresume_device(udev);

- /* release all urbs for this interface */
- usb_disable_interface(interface_to_usbdev(intf), intf);
+ /* Terminate all URBs for this interface unless the driver
+ * supports "soft" unbinding.
+ */
+ if (!driver->soft_unbind)
+ usb_disable_interface(udev, intf);

driver->disconnect(intf);

/* reset other interface state */
- usb_set_interface(interface_to_usbdev(intf),
- intf->altsetting[0].desc.bInterfaceNumber,
- 0);
+ usb_set_interface(udev, intf->altsetting[0].desc.bInterfaceNumber, 0);
usb_set_intfdata(intf, NULL);

intf->condition = USB_INTERFACE_UNBOUND;

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-***@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
g***@public.gmane.org
2008-05-08 23:22:46 UTC
Permalink
This is a note to let you know that I've just added the patch titled

Subject: USB: implement "soft" unbinding

to my gregkh-2.6 tree. Its filename is

usb-implement-soft-unbinding.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/
From: Alan Stern <stern-nwvwT67g6+6dFdvTe/***@public.gmane.org>
Date: Thu, 8 May 2008 11:54:37 -0400 (EDT)
Subject: USB: implement "soft" unbinding
To: Greg KH <greg-U8xfFu+***@public.gmane.org>
Cc: USB list <linux-usb-***@public.gmane.org>
Message-ID: <Pine.LNX.4.44L0.0805081152300.2188-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+***@public.gmane.org>


This patch (as1091) changes the way usbcore handles interface
unbinding. If the interface's driver supports "soft" unbinding (a new
flag in the driver structure) then in-flight URBs are not cancelled
and endpoints are not disabled. Instead the driver is allowed to
continue communicating with the device (although of course it should
stop before its disconnect routine returns).

The purpose of this change is to allow drivers to do a clean shutdown
when they get unbound from a device that is still plugged in. Killing
all the URBs and disabling the endpoints before calling the driver's
disconnect method doesn't give the driver any control over what
happens, and it can leave devices in indeterminate states. For
example, when usb-storage unbinds it doesn't want to stop while in the
middle of transmitting a SCSI command.

The soft_unbind flag is added because in the past, a number of drivers
have experienced problems related to ongoing I/O after their disconnect
routine returned. Hence "soft" unbinding is made available only to
drivers that claim to support it.

The patch also replaces "interface_to_usbdev(intf)" with "udev" in a
couple of places, a minor simplification.

Signed-off-by: Alan Stern <stern-nwvwT67g6+6dFdvTe/***@public.gmane.org>
Signed-off-by: Greg Kroah-Hartman <gregkh-***@public.gmane.org>

---
drivers/usb/core/driver.c | 11 ++++++-----
include/linux/usb.h | 3 +++
2 files changed, 9 insertions(+), 5 deletions(-)

--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -257,15 +257,16 @@ static int usb_unbind_interface(struct d
udev = interface_to_usbdev(intf);
error = usb_autoresume_device(udev);

- /* release all urbs for this interface */
- usb_disable_interface(interface_to_usbdev(intf), intf);
+ /* Terminate all URBs for this interface unless the driver
+ * supports "soft" unbinding.
+ */
+ if (!driver->soft_unbind)
+ usb_disable_interface(udev, intf);

driver->disconnect(intf);

/* reset other interface state */
- usb_set_interface(interface_to_usbdev(intf),
- intf->altsetting[0].desc.bInterfaceNumber,
- 0);
+ usb_set_interface(udev, intf->altsetting[0].desc.bInterfaceNumber, 0);
usb_set_intfdata(intf, NULL);

intf->condition = USB_INTERFACE_UNBOUND;
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -975,6 +975,8 @@ struct usbdrv_wrap {
* added to this driver by preventing the sysfs file from being created.
* @supports_autosuspend: if set to 0, the USB core will not allow autosuspend
* for interfaces bound to this driver.
+ * @soft_unbind: if set to 1, the USB core will not kill URBs and disable
+ * endpoints before calling the driver's disconnect method.
*
* USB interface drivers must provide a name, probe() and disconnect()
* methods, and an id_table. Other driver fields are optional.
@@ -1015,6 +1017,7 @@ struct usb_driver {
struct usbdrv_wrap drvwrap;
unsigned int no_dynamic_id:1;
unsigned int supports_autosuspend:1;
+ unsigned int soft_unbind:1;
};
#define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver)



Patches currently in gregkh-2.6 which might be from stern-nwvwT67g6+6dFdvTe/***@public.gmane.org are

usb/usb-storage-change-remaining-semaphore-to-completion.patch
usb/usb-storage-separate-dynamic-flags-from-fixed-flags.patch
usb/usb-implement-soft-unbinding.patch
usb/usb-storage-implement-soft-unbinding.patch
usb/usb-storage-unusual_devs-for-pandigital-picture-frame.patch
usb/usb-add-new-routine-for-checking-port-resume-type.patch
usb/usb-combine-hub_activate-and-hub_restart.patch
usb/usb-combine-hub_quiesce-and-hub_stop.patch
usb/usb-debounce-before-unregistering.patch
usb/usb-optimize-port-debouncing-during-hub-activation.patch
usb/usb-simplify-hub_restart-logic.patch
usb/usb-try-to-salvage-lost-power-sessions.patch
driver-core/pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch
driver-core/pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch
driver-core/pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch
usb.next/usb-create-attributes-before-sending-uevent.patch
usb.next/usb-support-for-the-et502hs-hdspa-modem-in-option-driver.patch
usb.next/usb-support-for-the-et502hs-hdspa-modem.patch
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-***@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Loading...