On Friday 09 January 2004 02:10, David Brownell wrote:
> Duncan Sands wrote:
> > Thanks a lot. This is extremely problematic then: in
> > usb_set_configuration, an interface's device structure will not be
> > completely initialized until we do device_add (&intf->dev);
> > ...
> > What to do?
>
> Hmm, good catch! Looks to me like usb_driver_claim_interface() will
> need to check whether the device has been added yet. Something like
> this should do it:
>
> intf->dev.driver = &driver->driver;
> intf->dev.driver_data = priv;
> if (!list_empty (&intf->dev.bus_list))
> device_bind_driver (&intf->dev);
>
> Then let usb_set_configuration() do the device_add(), which will
> automatically device_bind_driver() when dev->driver is set. (And
> will probe() otherwise.)
Hi Dave, I guess the same check is needed in usb_driver_release_interface,
in case someone claims and releases an interface before it has been
device_add()ed. This leads to the following behaviour though: if in your
probe() method you claim and release another interface that has been
device_add()ed, then disconnect() is called on it; but if you claim and release
an interface that has not yet been device_add()ed, then disconnect is not called.
Some might say this is inconsistent, but I think it is OK: it can be interpreted
as: disconnect() will only be called on interfaces that have been probe()ed.
On the other hand, there is the following variation: suppose interface 0
claims interface 1 when interface 0 is probe()ed. When interface 1 is
device_add()ed then it is not probe()ed because it was claimed. Suppose
now interface 2 releases interface 1 when interface 2 is probe()ed. Then
disconnect will be called on interface 1, even though its probe method
was not called. Oh well!
Duncan.
PS: It seems to work: (on top of my previous patch)
===== drivers/usb/core/usb.c 1.148 vs edited =====
--- 1.148/drivers/usb/core/usb.c Tue Jan 6 10:36:08 2004
+++ edited/drivers/usb/core/usb.c Sat Jan 10 00:30:46 2004
@@ -272,7 +272,12 @@
dev->driver = &driver->driver;
usb_set_intfdata(iface, priv);
- device_bind_driver(dev);
+
+ if (!list_empty (&dev->bus_list))
+ /* dev added to bus - safe to bind */
+ device_bind_driver(dev);
+ /* else pending device_add() will bind (without probe()) */
+
return 0;
}
@@ -299,7 +304,11 @@
if (!dev->driver || dev->driver != &driver->driver)
return;
- device_release_driver(dev);
+ if (!list_empty (&dev->bus_list))
+ device_release_driver(dev);
+
+ dev->driver = NULL;
+ usb_set_intfdata(iface, NULL);
}
/**
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel