Am Samstag, 23. Dezember 2006 00:37 schrieb J:

>  * usb_get_dev - increments the reference count of the
> usb device structure
>  * @dev: the device being referenced
>  *
>  * Each live reference to a device should be
> refcounted.
>  *
>  * Drivers for USB interfaces should normally record
> such references in
>  * their probe() methods, when they bind to an
> interface, and release
>  * them by calling usb_put_dev(), in their
> disconnect() methods.
> 
> But usb-serial.c breaks this rule because it calls
> usb_put_dev not in usb_serial_disconnect, but in 
> destroy_serial. destroy_serial is usually called
> from usb_serial_disconnect except in case of
> the serial_open/usb_serial_disconnect race condition.

This isn't a rule but a sugestion. The rules are:

1. You must balance get/put
2. You must not do IO after returning from disconnect

> So, this seems to prove that we cannot simply
> ref-count usb_serial and execute destroy_serial
> after usb_serial_disconnect already returned.

The use in the code is valid, but insufficient.
 
> This means that usb_serial_disconnect have to wait
> on serial_open and any other serial_* functions
> to finish. And the body of destroy_serial
> (or at least, most of it)
> should be returned back to usb_serial_disconnect

It is perfectly valid to do (in pseudocode)

disconnect:
lock()
device->disconnect_flag = 1;
unlock()
rest()
put()

io-method:
lock()
if (device->disconnect_flag)
        goto err_no_dev;
io()
unlock()

and to leave freeing the memory to refcounting

        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