All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: ftdi_sio: Fix locking for change_speed() function
@ 2010-03-08 13:10 Alessio Igor Bogani
  2010-03-08 17:35 ` Alan Cox
  0 siblings, 1 reply; 3+ messages in thread
From: Alessio Igor Bogani @ 2010-03-08 13:10 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Johan Hovold, Alan Cox, Daniel Mack, Mark J. Adamson, linux-usb,
	linux-kernel, Alessio Igor Bogani

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.

Signed-off-by: Alessio Igor Bogani <abogani@texware.it>
---
 drivers/usb/serial/ftdi_sio.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 6af0dfa..963a70f 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -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);
-- 
1.6.3.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: ftdi_sio: Fix locking for change_speed() function
  2010-03-08 13:10 [PATCH] USB: ftdi_sio: Fix locking for change_speed() function Alessio Igor Bogani
@ 2010-03-08 17:35 ` Alan Cox
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Cox @ 2010-03-08 17:35 UTC (permalink / raw)
  To: Alessio Igor Bogani
  Cc: Greg Kroah-Hartman, Johan Hovold, Alan Cox, Daniel Mack,
	Mark J. Adamson, linux-usb, linux-kernel

On Mon,  8 Mar 2010 14:10:03 +0100
Alessio Igor Bogani <abogani@texware.it> wrote:

> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] USB: ftdi_sio: Fix locking for change_speed() function
@ 2010-03-13 17:35 Alessio Igor Bogani
  0 siblings, 0 replies; 3+ messages in thread
From: Alessio Igor Bogani @ 2010-03-13 17:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Johan Hovold, Alan Cox, Daniel Mack, Mark Adamson, linux-usb,
	linux-kernel, Alessio Igor Bogani

The change_speed() function should be serialized against multiple calls.
Use the cfg_lock mutex to do this.

Signed-off-by: Alessio Igor Bogani <abogani@texware.it>
---
 drivers/usb/serial/ftdi_sio.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 6af0dfa..830f423 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -91,7 +91,7 @@ struct ftdi_private {
 	unsigned long tx_outstanding_bytes;
 	unsigned long tx_outstanding_urbs;
 	unsigned short max_packet_size;
-	struct mutex cfg_lock; /* Avoid mess by parallel calls of config ioctl() */
+	struct mutex cfg_lock; /* Avoid mess by parallel calls of config ioctl() and change_speed() */
 };
 
 /* struct ftdi_sio_quirk is used by devices requiring special attention. */
@@ -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);
-- 
1.6.3.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-13 17:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-08 13:10 [PATCH] USB: ftdi_sio: Fix locking for change_speed() function Alessio Igor Bogani
2010-03-08 17:35 ` Alan Cox
2010-03-13 17:35 Alessio Igor Bogani

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.