Am Freitag, 22. Dezember 2006 23:45 schrieb J:
> >     if (!port || port->serial->dev->state ==
> > USB_STATE_NOTATTACHED)
> 
> > There's no use checking for attachement. The state
> > may have changed.
> > In fact, if a device is disconnected via sysfs, this
> > code will happily write
> > to a device somebody else has claimed.
> 
> I don't understand. serial->dev is usb_device*
> and it is protected by ref counting (using
> usb_get_dev).
> So, it should not disappear or be claimed by
> anybody else, right?

Partially.
Yes, refcounting will make sure it does not disappear.
Refcounting will _not_ make sure it is not claimed.

The call path is as follows:
usbfs:
        /* disconnect kernel driver from interface */
        case USBDEVFS_DISCONNECT:

                down_write(&usb_bus_type.subsys.rwsem);
                if (intf->dev.driver) {
                        driver = to_usb_driver(intf->dev.driver);
                        dev_dbg (&intf->dev, "disconnect by usbfs\n");
                        usb_driver_release_interface(driver, intf);
                } else
                        retval = -ENODATA;
                up_write(&usb_bus_type.subsys.rwsem);
                break;
--
usb_driver_release_interface():
        /* don't release if the interface hasn't been added yet */
        if (device_is_registered(dev)) {
                iface->condition = USB_INTERFACE_UNBINDING;
                device_release_driver(dev);
        }
--
__device_release_driver():
                if (dev->bus && dev->bus->remove)
                        dev->bus->remove(dev);
                else if (drv->remove)
                        drv->remove(dev);

and a driver is unbound. After that ownership is in potential flux.

> As for the USB_STATE_NOTATTACHED, there is a long
> comment in hub.c about it. Also I see plenty of
> code, which checks it without any lock.
> So, I guess, it should not kill anybody.

It doesn't kill you.
USB_STATE_NOTATTACHED -> return with error code is valid.
However, the reverse is not.

        Regards
                Oliver

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to