Skip to content

Commit e33fe4d

Browse files
Oliver Neukumgregkh
authored andcommitted
USB: make sure usb serial drivers don't flush to logically disconnected devices
If disconnect() is called for a logical disconnect, no more IO must be done after disconnect() returns, or the old and new drivers may conflict. This patch avoids this by using the flag and lock introduced by the earlier patch for the mos7720 driver. Signed-off-by: Oliver Neukum <oneukum@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 004b4f2 commit e33fe4d

5 files changed

Lines changed: 35 additions & 21 deletions

File tree

‎drivers/usb/serial/mct_u232.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,21 +487,22 @@ static int mct_u232_open (struct usb_serial_port *port, struct file *filp)
487487
static void mct_u232_close (struct usb_serial_port *port, struct file *filp)
488488
{
489489
unsigned int c_cflag;
490-
unsigned long flags;
491490
unsigned int control_state;
492491
struct mct_u232_private *priv = usb_get_serial_port_data(port);
493492
dbg("%s port %d", __FUNCTION__, port->number);
494493

495494
if (port->tty) {
496495
c_cflag = port->tty->termios->c_cflag;
497-
if (c_cflag & HUPCL) {
498-
/* drop DTR and RTS */
499-
spin_lock_irqsave(&priv->lock, flags);
500-
priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
501-
control_state = priv->control_state;
502-
spin_unlock_irqrestore(&priv->lock, flags);
503-
mct_u232_set_modem_ctrl(port->serial, control_state);
496+
mutex_lock(&port->serial->disc_mutex);
497+
if (c_cflag & HUPCL && !port->serial->disconnected) {
498+
/* drop DTR and RTS */
499+
spin_lock_irq(&priv->lock);
500+
priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
501+
control_state = priv->control_state;
502+
spin_unlock_irq(&priv->lock);
503+
mct_u232_set_modem_ctrl(port->serial, control_state);
504504
}
505+
mutex_unlock(&port->serial->disc_mutex);
505506
}
506507

507508

‎drivers/usb/serial/option.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,10 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
641641
portdata->dtr_state = 0;
642642

643643
if (serial->dev) {
644-
option_send_setup(port);
644+
mutex_lock(&serial->disc_mutex);
645+
if (!serial->disconnected)
646+
option_send_setup(port);
647+
mutex_unlock(&serial->disc_mutex);
645648

646649
/* Stop reading/writing urbs */
647650
for (i = 0; i < N_IN_URB; i++)

‎drivers/usb/serial/sierra.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,10 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp)
597597
portdata->dtr_state = 0;
598598

599599
if (serial->dev) {
600-
sierra_send_setup(port);
600+
mutex_lock(&serial->disc_mutex);
601+
if (!serial->disconnected)
602+
sierra_send_setup(port);
603+
mutex_unlock(&serial->disc_mutex);
601604

602605
/* Stop reading/writing urbs */
603606
for (i = 0; i < N_IN_URB; i++)

‎drivers/usb/serial/visor.c‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,20 @@ static void visor_close (struct usb_serial_port *port, struct file * filp)
349349
usb_kill_urb(port->read_urb);
350350
usb_kill_urb(port->interrupt_in_urb);
351351

352-
/* Try to send shutdown message, if the device is gone, this will just fail. */
353-
transfer_buffer = kmalloc (0x12, GFP_KERNEL);
354-
if (transfer_buffer) {
355-
usb_control_msg (port->serial->dev,
356-
usb_rcvctrlpipe(port->serial->dev, 0),
357-
VISOR_CLOSE_NOTIFICATION, 0xc2,
358-
0x0000, 0x0000,
359-
transfer_buffer, 0x12, 300);
360-
kfree (transfer_buffer);
352+
mutex_lock(&port->serial->disc_mutex);
353+
if (!port->serial->disconnected) {
354+
/* Try to send shutdown message, unless the device is gone */
355+
transfer_buffer = kmalloc (0x12, GFP_KERNEL);
356+
if (transfer_buffer) {
357+
usb_control_msg (port->serial->dev,
358+
usb_rcvctrlpipe(port->serial->dev, 0),
359+
VISOR_CLOSE_NOTIFICATION, 0xc2,
360+
0x0000, 0x0000,
361+
transfer_buffer, 0x12, 300);
362+
kfree (transfer_buffer);
363+
}
361364
}
365+
mutex_lock(&port->serial->disc_mutex);
362366

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

‎drivers/usb/serial/whiteheat.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,14 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
658658
struct list_head *tmp2;
659659

660660
dbg("%s - port %d", __FUNCTION__, port->number);
661-
661+
662+
mutex_lock(&port->serial->disc_mutex);
662663
/* filp is NULL when called from usb_serial_disconnect */
663-
if (filp && (tty_hung_up_p(filp))) {
664+
if ((filp && (tty_hung_up_p(filp))) || port->serial->disconnected) {
665+
mutex_unlock(&port->serial->disc_mutex);
664666
return;
665667
}
668+
mutex_unlock(&port->serial->disc_mutex);
666669

667670
port->tty->closing = 1;
668671

0 commit comments

Comments
 (0)