Re: [PATCH 1/2] hid2hci: iterate libusb devices twice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 29 Jul 2009, Kay Sievers wrote:

> Yeah, I'm sure. The thing is that the kernel USB code for some weird
> reason returns -ENOENT instead -ENODEV -- hence the misleading error
> string.

That return code can easily be changed.

> Alan, I suspect (haven't checked) that at the time we get the event
> for the usb_device, the device is not ready to be handled by usbfs
> operations. Is that likely? And if, any idea how, and until which
> point, to delay the usb_device uevent, in which we hook in to do the
> usbfs actions from userspace?

There are two aspects we have to consider: usbfs device nodes
(/dev/bus/usb/*/*) and usbfs file nodes (/proc/bus/usb/*/*).  The 
device nodes are created by udev whereas the file nodes are created by 
the kernel (if CONFIG_USB_DEVICEFS is enabled).  Nowadays most people 
use the device nodes, but embedded systems without udev may want to 
rely on the file nodes.


With the device nodes, the problem is this: usbdev_open() looks up
dev_t values by calling bus_find_device().  But devices are added to
the bus's list by bus_attach_device(), which isn't called until after
the KOBJ_ADD uevent is sent.  Hence there's a window after the uevent
is issued and before the device can be looked up on the bus.  That's
probably what's happening here.

Interchanging bus_attach_device() and kobject_uevent() in device_add()  
would solve this problem, but it would introduce other problems.  In
particular, if a probe routine registered a child device then the 
child's uevent would be sent before the parent's!

You know, the real problem may lie in bus_attach_device().  If probing
fails then it doesn't add the device to the bus -- and it doesn't even
return an error code when this happens.  One can argue that the device
should _always_ be added to the bus, regardless of whether a suitable
driver can be found.  If you accept that argument then linking the
device into the bus's list should be moved up into bus_add_device(),
which is called before the uevent.  Indeed, each of those two routines
has a comment in the kerneldoc saying "Add the device to its bus's list
of devices."  They can't both be right!


There's also a problem with usbfs file nodes.  The file nodes are 
created by the device's probe routine.  So again, if the uevent comes 
before probing then it will come before the file nodes exist.  I 
suppose we could create the file nodes earlier, before the device is 
registered, but is this really a good idea?

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux