diff options
author | David Woodhouse <dwmw2@infradead.org> | 2009-05-18 08:07:35 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-05-18 11:37:15 -0400 |
commit | 80193195f87ebca6d7417516d6edeb3969631c15 (patch) | |
tree | 870be37dde8e7d2524c2cce5a4571d5a41f0a80a /drivers | |
parent | dbf8c11f821b6ff83302c34f2403b4f7231f50ae (diff) |
Fix oops on close of hot-unplugged FTDI serial converter
Commit c45d6320 ("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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/serial/ftdi_sio.c | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 0ab8474b00cb..d9fcdaedf389 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -1487,14 +1487,7 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port) | |||
1487 | 1487 | ||
1488 | remove_sysfs_attrs(port); | 1488 | remove_sysfs_attrs(port); |
1489 | 1489 | ||
1490 | /* all open ports are closed at this point | 1490 | kref_put(&priv->kref, ftdi_sio_priv_release); |
1491 | * (by usbserial.c:__serial_close, which calls ftdi_close) | ||
1492 | */ | ||
1493 | |||
1494 | if (priv) { | ||
1495 | usb_set_serial_port_data(port, NULL); | ||
1496 | kref_put(&priv->kref, ftdi_sio_priv_release); | ||
1497 | } | ||
1498 | 1491 | ||
1499 | return 0; | 1492 | return 0; |
1500 | } | 1493 | } |