All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] USB: serial: cp210x: Fix error 32 when hardware flow control  is enabled.
@ 2021-01-21  9:52 Pho Tran
  2021-01-25 13:47 ` Johan Hovold
  0 siblings, 1 reply; 2+ messages in thread
From: Pho Tran @ 2021-01-21  9:52 UTC (permalink / raw)
  To: gregkh, johan; +Cc: linux-kernel, linux-usb

Fix error 32 returned by CP210X_SET_MHS when hardware flow control is enabled.

The root cause of error 32 is that user application (CoolTerm, linux-serial-test)
opened cp210x device with hardware flow control then attempt to control RTS/DTR pins.
In hardware flow control, RTS/DTR pins will be controlled by hardware only,
any attempt to control those pins will cause error 32 from the device.
This fix will block MHS command(command to control RTS/DTR pins) to the device
if hardware flow control is being used.

Signed-off-by: Pho Tran <pho.tran@silabs.com>
---
01/21/2021: Patch v3 modified based on comment from Greg Kroah-Hartman <gregkh@linuxfoundation.org>
01/19/2021: Patch v2  Modified based on comment from Johan Hovold <johan@kernel.org>
and Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/serial/cp210x.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index fbb10dfc56e3..814dff5fee98 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1204,7 +1204,12 @@ static int cp210x_tiocmset(struct tty_struct *tty,
 		unsigned int set, unsigned int clear)
 {
 	struct usb_serial_port *port = tty->driver_data;
-	return cp210x_tiocmset_port(port, set, clear);
+
+	/* Don't send SET_MHS command if device in hardware flow control mode. */
+	if (C_CRTSCTS(tty))
+		return 0;
+	else
+		return cp210x_tiocmset_port(port, set, clear);
 }
 
 static int cp210x_tiocmset_port(struct usb_serial_port *port,
-- 
2.17.1


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

* Re: [PATCH v4] USB: serial: cp210x: Fix error 32 when hardware flow control  is enabled.
  2021-01-21  9:52 [PATCH v4] USB: serial: cp210x: Fix error 32 when hardware flow control is enabled Pho Tran
@ 2021-01-25 13:47 ` Johan Hovold
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2021-01-25 13:47 UTC (permalink / raw)
  To: Pho Tran; +Cc: gregkh, johan, linux-kernel, linux-usb

On Thu, Jan 21, 2021 at 09:52:23AM +0000, Pho Tran wrote:
> Fix error 32 returned by CP210X_SET_MHS when hardware flow control is enabled.
> 
> The root cause of error 32 is that user application (CoolTerm, linux-serial-test)
> opened cp210x device with hardware flow control then attempt to control RTS/DTR pins.
> In hardware flow control, RTS/DTR pins will be controlled by hardware only,
> any attempt to control those pins will cause error 32 from the device.
> This fix will block MHS command(command to control RTS/DTR pins) to the device
> if hardware flow control is being used.
> 
> Signed-off-by: Pho Tran <pho.tran@silabs.com>
> ---
> 01/21/2021: Patch v3 modified based on comment from Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 01/19/2021: Patch v2  Modified based on comment from Johan Hovold <johan@kernel.org>
> and Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Giving credit in the commit log is nice, but this still doesn't say
anything about *what* you changed.

> ---
>  drivers/usb/serial/cp210x.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> index fbb10dfc56e3..814dff5fee98 100644
> --- a/drivers/usb/serial/cp210x.c
> +++ b/drivers/usb/serial/cp210x.c
> @@ -1204,7 +1204,12 @@ static int cp210x_tiocmset(struct tty_struct *tty,
>  		unsigned int set, unsigned int clear)
>  {
>  	struct usb_serial_port *port = tty->driver_data;
> -	return cp210x_tiocmset_port(port, set, clear);
> +
> +	/* Don't send SET_MHS command if device in hardware flow control mode. */
> +	if (C_CRTSCTS(tty))
> +		return 0;

You didn't reply to my comments that what should be done here is to
disable auto-RTS when clearing TIOCM_RST and re-enable it when setting
the same bit. If you disagree with review feedback you need to say so
and not just resend a new version of your patch without an explanation.

Note that the above would also needlessly prevent DTR from being changed
whenever auto-RTS is enabled and return success instead of an error to
user space.

My suggestion for how to suppress the error message from dtr_rts()
suffers from the same problem so I've updated that patch and implemented
proper RTS handling in the driver now.

This takes care not only of the SET_MHS error messages, but also makes
sure that RTS can always be deasserted and some other related issues
with regards to modem control.

> +	else
> +		return cp210x_tiocmset_port(port, set, clear);
>  }
>  
>  static int cp210x_tiocmset_port(struct usb_serial_port *port,

Johan

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

end of thread, other threads:[~2021-01-25 13:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21  9:52 [PATCH v4] USB: serial: cp210x: Fix error 32 when hardware flow control is enabled Pho Tran
2021-01-25 13:47 ` Johan Hovold

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.