Skip to contentSkip to conversation

USB: ftdi_sio: Fix locking for change_speed() function

PATCH In review Alessio Igor Bogani 2 participants 2 messages Mar 8, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB: ftdi_sio: Fix locking for change_speed() function

The change_speed() function set the baudrate of the device: so this function should be serialized against multiple calls. Use the cfg_lock mutex to do this.

---
 drivers/usb/serial/ftdi_sio.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/usb/serial/ftdi_sio.c +3 -1
index 6af0dfa..963a70f 100644
@@ -1272,8 +1272,8 @@ check_and_exit:
 	     (priv->flags & ASYNC_SPD_MASK)) ||
 	    (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
 	     (old_priv.custom_divisor != priv->custom_divisor))) {
-		mutex_unlock(&priv->cfg_lock);
 		change_speed(tty, port);
+		mutex_unlock(&priv->cfg_lock);
 	}
 	else
 		mutex_unlock(&priv->cfg_lock);
@@ -2264,9 +2264,11 @@ static void ftdi_set_termios(struct tty_struct *tty,
 		clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
 	} else {
 		/* set the baudrate determined before */
+		mutex_lock(&priv->cfg_lock);
 		if (change_speed(tty, port))
 			dev_err(&port->dev, "%s urb failed to set baudrate\n",
 				__func__);
+		mutex_unlock(&priv->cfg_lock);
 		/* Ensure RTS and DTR are raised when baudrate changed from 0 */
 		if (!old_termios || (old_termios->c_cflag & CBAUD) == B0)
 			set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 2 lines · On Mon, 8 Mar 2010 14:10:03 +0100 Alessio Igor Bogani <[email protected]>…

The change_speed() function set the baudrate of the device: so this function should be serialized against multiple calls. Use the cfg_lock mutex to do this.

Should be ok anyway the set_termios callback occurs under the tty termios lock, and will not occur in parallel with an initial open or final close.

Alan