On Thu, 11 Aug 2005, Greg KH wrote:

> > Well, there's still a little bit to discuss.  Pat mentioned that in
> > general, the remove method is supposed to handle children.  Presumably
> > this applies to the usb_generic driver.  Should it try to unconfigure a
> > USB device (thus deleting the interfaces) when it is unbound?  Or am I 
> > going overboard here, considering that usb_generic is pretty much a 
> > do-nothing placeholder?
> 
> It is a "placeholder" but an important one (it wouldn't work without
> it...)  I hadn't thought about unbinding that "driver" before, I guess
> if it's not too much trouble we should also support that kind of
> unbinding.  That would allow people to test "disconnect" without ever
> removing a device, much like the "fakephp" driver allows you to do this
> for pci devices.

I'm not quite sure what you mean.  Unbinding usb_generic wouldn't be quite
like a disconnect, because it would leave the usb_device intact.  But it
would be like a disconnect in that the interfaces with their associated
drivers would go away.  However, people can accomplish the same thing
right now by writing '0' to /sys/device/.../bConfigurationValue (unless
the device perversely has a configuration 0).

Is the patch below what you had in mind?  To tell the truth, I'm not sure
that it's needed at all.  The usb_generic "driver" doesn't serve any
purpose other than to mark USB devices (as opposed to interfaces) and to
provide suspend/resume methods.

As for supporting this kind of unbinding... as things stand we have no
choice.  There's currently no way to prevent the sysfs unbind attribute
from doing its thing.  I wonder if we wouldn't be better off finding a way 
for a driver to indicate that it should never be unbound, until the device 
is removed.

If you like the patch, I'll resend it with a real Changelog message.

Alan Stern



Index: usb-2.6/drivers/usb/core/usb.c
===================================================================
--- usb-2.6.orig/drivers/usb/core/usb.c
+++ usb-2.6/drivers/usb/core/usb.c
@@ -65,6 +65,16 @@ static int generic_probe (struct device 
 }
 static int generic_remove (struct device *dev)
 {
+       struct usb_device *udev = to_usb_device(dev);
+
+       /* if this is only an unbind, not a physical disconnect, then
+        * unconfigure the device */
+       if (udev->state == USB_STATE_CONFIGURED)
+               usb_set_configuration(udev, 0);
+
+       /* in case the call failed or the device was suspended */
+       if (udev->state >= USB_STATE_CONFIGURED)
+               usb_disable_device(udev, 0);
        return 0;
 }
 



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to