Skip to content

Commit

Permalink
Fix oops on close of hot-unplugged FTDI serial converter
Browse files Browse the repository at this point in the history
Commit c45d632 ("fix reference counting of ftdi_private") stopped
ftdi_sio_port_remove() from directly freeing the port-private data, with
the intention if the port was still open, it would be freed when
ftdi_close() is eventually called and releases the last refcount on the
structure.

That's all very well, but ftdi_sio_port_remove() still contains a call
to usb_set_serial_port_data(port, NULL) -- so by the time we get to
ftdi_close() for the port which was unplugged, it _still_ oopses on
dereferencing that NULL pointer, as it did before (and does in 2.6.29).

The fix is just not to clear the private data in ftdi_sio_port_remove().
Then the refcount is properly reduced to zero when the final kref_put()
happens in ftdi_close().

Remove a bogus comment too, while we're at it. And stop doing things
inside "if (priv)" -- it must _always_ be there.

Based loosely on an earlier patch by Daniel Mack, and suggestions by
Alan Stern.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Tested-by: Daniel Mack <daniel@caiaq.de>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
David Woodhouse authored and Linus Torvalds committed May 18, 2009
1 parent dbf8c11 commit 8019319
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions drivers/usb/serial/ftdi_sio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1487,14 +1487,7 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)

remove_sysfs_attrs(port);

/* all open ports are closed at this point
* (by usbserial.c:__serial_close, which calls ftdi_close)
*/

if (priv) {
usb_set_serial_port_data(port, NULL);
kref_put(&priv->kref, ftdi_sio_priv_release);
}
kref_put(&priv->kref, ftdi_sio_priv_release);

return 0;
}
Expand Down

0 comments on commit 8019319

Please sign in to comment.