Messages in this thread | | | Date | Tue, 11 Jan 2005 13:10:50 +1030 | Subject | RFC: Code to snatch a device from a generic driver | From | Ron <> |
| |
Hi,
We're presently working on enabling the cpad[1] and wacom kernel modules to retrieve their particular devices from a more generic driver that may have already claimed them, without resorting to patching other drivers as we see with the quirks in usbhid. In 2.6 we can no longer even pull the 'add below hid' stunt that got us by from userspace in 2.4 [2] -- however the new driver core model as I understand it seems like it should be able to handle this very nicely from within the module itself.
The following code (derived from a patch sent to me by Jan Steinhoff) seems to do the job, but is surely not correct yet.
The cpad really is a one off device at present, so it can get by with something like this at this stage, but the wacom driver will need to iterate over its id table if it is to do it the same way. And if I haven't totally botched the locking below[3] that means it will need to collect the locks of all the devices it finds before it registers with they usb core -- if there is more than one such device attached to the system.
Which seems to me like a sure recipe for occasional deadlock, unless there is a guarantee I'm missing here somewhere.
I believe that Greg KH has a pretty good handle on this, and possibly this is the issue he is aiming to fix still, but I think there are surely other people who need to do this too so I'm posting here now, because the following doesn't crash under the testing I've given it so far, so only more eyeballs or more testing is going to tell me what else may be wrong with it, and tell us what still needs to be mended in the kernel proper.
Comments from anyone with an interest in this would be greatly appreciated. Please cc, it's been many years since my inbox could cope with vger.
thanks, Ron
static int __init cpad_init(void) { struct usb_device *udev = usb_find_device(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_CPAD); if (udev) { down( &udev->serialize ); down_write( &udev->dev.bus->subsys.rwsem );
struct usb_interface *interface = usb_ifnum_to_if(udev, 0);
if (interface && usb_interface_claimed(interface)) { info("releasing cPad from generic driver '%s'.", interface->dev.driver->name); usb_driver_release_interface( to_usb_driver(interface->dev.driver),interface); }
up_write( &udev->dev.bus->subsys.rwsem ); usb_put_dev(udev); }
int result = usb_register(&cpad_driver);
if (udev) up( &udev->serialize );
if (result == 0) { cpad_procfs_init(); info(DRIVER_DESC " " DRIVER_VERSION); } else err("usb_register failed. Error number %d", result);
return result; }
[1] The cPad is an lcd backed touchpad from synaptics, the module is not in the mainline kernel yet, we were too late for 2.4 and slow to get onboard 2.6 ... (we being the authors, none of us are associated with synaptics) [2] without some nasty acrobatics [3] which is quite possible, I'm still very green to kernel 2.6
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |