aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/usb-serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/usb-serial.c')
-rw-r--r--drivers/usb/serial/usb-serial.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 794b5ffe4397..080ade223d53 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -269,15 +269,19 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
269 return; 269 return;
270 } 270 }
271 271
272 --port->port.count; 272 if (port->port.count == 1)
273 if (port->port.count == 0)
274 /* only call the device specific close if this 273 /* only call the device specific close if this
275 * port is being closed by the last owner */ 274 * port is being closed by the last owner. Ensure we do
275 * this before we drop the port count. The call is protected
276 * by the port mutex
277 */
276 port->serial->type->close(tty, port, filp); 278 port->serial->type->close(tty, port, filp);
277 279
278 if (port->port.count == (port->console? 1 : 0)) { 280 if (port->port.count == (port->console ? 2 : 1)) {
279 struct tty_struct *tty = tty_port_tty_get(&port->port); 281 struct tty_struct *tty = tty_port_tty_get(&port->port);
280 if (tty) { 282 if (tty) {
283 /* We must do this before we drop the port count to
284 zero. */
281 if (tty->driver_data) 285 if (tty->driver_data)
282 tty->driver_data = NULL; 286 tty->driver_data = NULL;
283 tty_port_tty_set(&port->port, NULL); 287 tty_port_tty_set(&port->port, NULL);
@@ -285,13 +289,14 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
285 } 289 }
286 } 290 }
287 291
288 if (port->port.count == 0) { 292 if (port->port.count == 1) {
289 mutex_lock(&port->serial->disc_mutex); 293 mutex_lock(&port->serial->disc_mutex);
290 if (!port->serial->disconnected) 294 if (!port->serial->disconnected)
291 usb_autopm_put_interface(port->serial->interface); 295 usb_autopm_put_interface(port->serial->interface);
292 mutex_unlock(&port->serial->disc_mutex); 296 mutex_unlock(&port->serial->disc_mutex);
293 module_put(port->serial->type->driver.owner); 297 module_put(port->serial->type->driver.owner);
294 } 298 }
299 --port->port.count;
295 300
296 mutex_unlock(&port->mutex); 301 mutex_unlock(&port->mutex);
297 usb_serial_put(port->serial); 302 usb_serial_put(port->serial);
@@ -334,6 +339,10 @@ static int serial_chars_in_buffer(struct tty_struct *tty)
334 dbg("%s = port %d", __func__, port->number); 339 dbg("%s = port %d", __func__, port->number);
335 340
336 WARN_ON(!port->port.count); 341 WARN_ON(!port->port.count);
342 /* if the device was unplugged then any remaining characters
343 fell out of the connector ;) */
344 if (port->serial->disconnected)
345 return 0;
337 /* pass on to the driver specific version of this function */ 346 /* pass on to the driver specific version of this function */
338 return port->serial->type->chars_in_buffer(tty); 347 return port->serial->type->chars_in_buffer(tty);
339} 348}
@@ -373,9 +382,7 @@ static int serial_ioctl(struct tty_struct *tty, struct file *file,
373 /* pass on to the driver specific version of this function 382 /* pass on to the driver specific version of this function
374 if it is available */ 383 if it is available */
375 if (port->serial->type->ioctl) { 384 if (port->serial->type->ioctl) {
376 lock_kernel();
377 retval = port->serial->type->ioctl(tty, file, cmd, arg); 385 retval = port->serial->type->ioctl(tty, file, cmd, arg);
378 unlock_kernel();
379 } else 386 } else
380 retval = -ENOIOCTLCMD; 387 retval = -ENOIOCTLCMD;
381 return retval; 388 return retval;
@@ -404,11 +411,8 @@ static int serial_break(struct tty_struct *tty, int break_state)
404 WARN_ON(!port->port.count); 411 WARN_ON(!port->port.count);
405 /* pass on to the driver specific version of this function 412 /* pass on to the driver specific version of this function
406 if it is available */ 413 if it is available */
407 if (port->serial->type->break_ctl) { 414 if (port->serial->type->break_ctl)
408 lock_kernel();
409 port->serial->type->break_ctl(tty, break_state); 415 port->serial->type->break_ctl(tty, break_state);
410 unlock_kernel();
411 }
412 return 0; 416 return 0;
413} 417}
414 418