usb-serial: change referencing of port and serial structures
commitc9fb3ded7a8a6769f3bcb3ef3d9aed61d3e376a9
authorAlan Stern <stern@rowland.harvard.edu>
Tue, 1 Sep 2009 15:38:34 +0000 (1 11:38 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 5 Oct 2009 16:32:37 +0000 (5 09:32 -0700)
treeed67cfd4b161b270cf020d24baaf6759cdf15cff
parent17fd426331d1e4611654985dd545a52d200dd9d1
usb-serial: change referencing of port and serial structures

commit 41bd34ddd7aa46dbc03b5bb33896e0fa8100fe7b upstream.

This patch (as1284) changes the referencing of the usb_serial and
usb_serial_port structures in usb-serial.c.  It's not feasible to make
the port structures keep a reference to the serial structure, because
the ports need to remain in existence when serial is released -- quite
a few of the drivers expect this.  Consequently taking a reference
to the port when the device file is open is insufficient; such a
reference would not pin serial.

To fix this, we now take a reference to serial when the device file is
opened.  The final put_device() for the ports occurs in
destroy_serial(), so that the ports will last as long as they are
needed.

The patch initializes all the port devices, including those in the
unused "fake" ports.  This makes the code more uniform because they
can all be released in the same way.  The error handling code in
usb_serial_probe() is much simplified by this approach; instead of
freeing everything by hand we can use a single usb_serial_put() call.

Also simplified is the port-release mechanism.  Instead of being two
separate routines, port_release() and port_free() can be combined into
one.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/serial/usb-serial.c