Skip to content

Commit 95bef01

Browse files
Oliver Neukumgregkh
Oliver Neukum
authored andcommitted
USB: more serial drivers writing after disconnect
this covers the rest of the obvious cases by using the flags and locks to guard against disconnect which were introduced in the earlier patch against mos7720. Signed-off-by: Oliver Neukum <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e33fe4d commit 95bef01

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

drivers/usb/serial/airprime.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ static void airprime_close(struct usb_serial_port *port, struct file * filp)
217217
priv->rts_state = 0;
218218
priv->dtr_state = 0;
219219

220-
airprime_send_setup(port);
220+
mutex_lock(&port->serial->disc_mutex);
221+
if (!port->serial->disconnected)
222+
airprime_send_setup(port);
223+
mutex_lock(&port->serial->disc_mutex);
221224

222225
for (i = 0; i < NUM_READ_URBS; ++i) {
223226
usb_kill_urb (priv->read_urbp[i]);

drivers/usb/serial/cp2101.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ static void cp2101_close (struct usb_serial_port *port, struct file * filp)
348348
usb_kill_urb(port->write_urb);
349349
usb_kill_urb(port->read_urb);
350350

351-
cp2101_set_config_single(port, CP2101_UART, UART_DISABLE);
351+
mutex_lock(&port->serial->disc_mutex);
352+
if (!port->serial->disconnected)
353+
cp2101_set_config_single(port, CP2101_UART, UART_DISABLE);
354+
mutex_unlock(&port->serial->disc_mutex);
352355
}
353356

354357
/*

drivers/usb/serial/ftdi_sio.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,8 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
11981198

11991199
dbg("%s", __FUNCTION__);
12001200

1201-
if (c_cflag & HUPCL){
1201+
mutex_lock(&port->serial->disc_mutex);
1202+
if (c_cflag & HUPCL && !port->serial->disconnected){
12021203
/* Disable flow control */
12031204
if (usb_control_msg(port->serial->dev,
12041205
usb_sndctrlpipe(port->serial->dev, 0),
@@ -1212,6 +1213,7 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
12121213
/* drop RTS and DTR */
12131214
clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
12141215
} /* Note change no line if hupcl is off */
1216+
mutex_unlock(&port->serial->disc_mutex);
12151217

12161218
/* cancel any scheduled reading */
12171219
cancel_delayed_work(&priv->rx_work);

drivers/usb/serial/garmin_gps.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -1020,19 +1020,26 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
10201020
if (!serial)
10211021
return;
10221022

1023-
garmin_clear(garmin_data_p);
1023+
mutex_lock(&port->serial->disc_mutex);
1024+
if (!port->serial->disconnected)
1025+
garmin_clear(garmin_data_p);
10241026

10251027
/* shutdown our urbs */
10261028
usb_kill_urb (port->read_urb);
10271029
usb_kill_urb (port->write_urb);
10281030

1029-
if (noResponseFromAppLayer(garmin_data_p) ||
1030-
((garmin_data_p->flags & CLEAR_HALT_REQUIRED) != 0)) {
1031-
process_resetdev_request(port);
1032-
garmin_data_p->state = STATE_RESET;
1031+
if (!port->serial->disconnected) {
1032+
if (noResponseFromAppLayer(garmin_data_p) ||
1033+
((garmin_data_p->flags & CLEAR_HALT_REQUIRED) != 0)) {
1034+
process_resetdev_request(port);
1035+
garmin_data_p->state = STATE_RESET;
1036+
} else {
1037+
garmin_data_p->state = STATE_DISCONNECTED;
1038+
}
10331039
} else {
10341040
garmin_data_p->state = STATE_DISCONNECTED;
10351041
}
1042+
mutex_unlock(&port->serial->disc_mutex);
10361043
}
10371044

10381045

drivers/usb/serial/visor.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static void visor_close (struct usb_serial_port *port, struct file * filp)
362362
kfree (transfer_buffer);
363363
}
364364
}
365-
mutex_lock(&port->serial->disc_mutex);
365+
mutex_unlock(&port->serial->disc_mutex);
366366

367367
if (stats)
368368
dev_info(&port->dev, "Bytes In = %d Bytes Out = %d\n",

0 commit comments

Comments
 (0)