aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorAlan Cox <alan@lxorguk.ukuu.org.uk>2009-07-27 19:34:58 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-07-27 20:26:23 -0400
commitc56d300086140c93dc3390e5300fd17df802ec0e (patch)
treecc80d5acf9abe433573efe5d610b0f19df04f5d8 /drivers/usb
parentfc013a58859b7cf85e53a05804a74952fe0a4117 (diff)
usb_serial: Fix remaining ref count/lock bugs
This fixes - locking bug that was hidden by ecc2e05e739c30870c8e4f252b63a0c4041f2724 - Regression #13821 - Spurious warning when closing and blocking for data write out With these changes my PL2303 always ends up as ttyUSB0 when it should and the module refcounts stay correct. I'll do a more wholesale split & tidy of _open in the next release or two as we get a standard tty_port_open and port->ops->init port->ops->shutdown call backs. Copy sent to Alan Stern and Carlos Mafra just to confirm it fixes all the reports but it passes local testing with the same hardware as Alan Stern. Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/serial/usb-serial.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 3c8923f62ed1..99188c92068b 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -32,6 +32,7 @@
32#include <linux/mutex.h> 32#include <linux/mutex.h>
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/uaccess.h> 34#include <linux/uaccess.h>
35#include <linux/serial.h>
35#include <linux/usb.h> 36#include <linux/usb.h>
36#include <linux/usb/serial.h> 37#include <linux/usb/serial.h>
37#include "pl2303.h" 38#include "pl2303.h"
@@ -184,6 +185,7 @@ static int serial_open (struct tty_struct *tty, struct file *filp)
184 struct usb_serial_port *port; 185 struct usb_serial_port *port;
185 unsigned int portNumber; 186 unsigned int portNumber;
186 int retval = 0; 187 int retval = 0;
188 int first = 0;
187 189
188 dbg("%s", __func__); 190 dbg("%s", __func__);
189 191
@@ -223,7 +225,7 @@ static int serial_open (struct tty_struct *tty, struct file *filp)
223 225
224 /* If the console is attached, the device is already open */ 226 /* If the console is attached, the device is already open */
225 if (port->port.count == 1 && !port->console) { 227 if (port->port.count == 1 && !port->console) {
226 228 first = 1;
227 /* lock this module before we call it 229 /* lock this module before we call it
228 * this may fail, which means we must bail out, 230 * this may fail, which means we must bail out,
229 * safe because we are called with BKL held */ 231 * safe because we are called with BKL held */
@@ -246,13 +248,21 @@ static int serial_open (struct tty_struct *tty, struct file *filp)
246 if (retval) 248 if (retval)
247 goto bailout_interface_put; 249 goto bailout_interface_put;
248 mutex_unlock(&serial->disc_mutex); 250 mutex_unlock(&serial->disc_mutex);
251 set_bit(ASYNCB_INITIALIZED, &port->port.flags);
249 } 252 }
250 mutex_unlock(&port->mutex); 253 mutex_unlock(&port->mutex);
251 /* Now do the correct tty layer semantics */ 254 /* Now do the correct tty layer semantics */
252 retval = tty_port_block_til_ready(&port->port, tty, filp); 255 retval = tty_port_block_til_ready(&port->port, tty, filp);
253 if (retval == 0) 256 if (retval == 0) {
257 if (!first)
258 usb_serial_put(serial);
254 return 0; 259 return 0;
255 260 }
261 mutex_lock(&port->mutex);
262 if (first == 0)
263 goto bailout_mutex_unlock;
264 /* Undo the initial port actions */
265 mutex_lock(&serial->disc_mutex);
256bailout_interface_put: 266bailout_interface_put:
257 usb_autopm_put_interface(serial->interface); 267 usb_autopm_put_interface(serial->interface);
258bailout_module_put: 268bailout_module_put:
@@ -411,7 +421,6 @@ static int serial_chars_in_buffer(struct tty_struct *tty)
411 struct usb_serial_port *port = tty->driver_data; 421 struct usb_serial_port *port = tty->driver_data;
412 dbg("%s = port %d", __func__, port->number); 422 dbg("%s = port %d", __func__, port->number);
413 423
414 WARN_ON(!port->port.count);
415 /* if the device was unplugged then any remaining characters 424 /* if the device was unplugged then any remaining characters
416 fell out of the connector ;) */ 425 fell out of the connector ;) */
417 if (port->serial->disconnected) 426 if (port->serial->disconnected)