diff options
Diffstat (limited to 'drivers/usb/serial/usb-serial.c')
-rw-r--r-- | drivers/usb/serial/usb-serial.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 794b5ffe4397..aafa684a900f 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); |