]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
serial: 8250_fintek: Return -EINVAL on invalid configuration
authorRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Mon, 6 Nov 2017 10:49:12 +0000 (11:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Nov 2017 12:09:35 +0000 (13:09 +0100)
Hardware does not support having the same RTS level during RX and TX
when RS485 mode is on (URA in Fintek terminology).

The manufacturer has also confirmed that the delays are not enabled if
the RS485 mode is not enabled.

Therefore we should return -EINVAL if the user wants to have the same
value for RTS_ON_SEND and RTS_AFTER_SEND.

Cc: "Ji-Ze Hong (Peter Hong)" <hpeter@gmail.com>
Cc: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250_fintek.c

index be7029f2391eb3c44ad7480995dacedce1d659dc..6c7910d8e136c57330efbdcd4f1e4e2613de9229 100644 (file)
@@ -197,10 +197,17 @@ static int fintek_8250_rs485_config(struct uart_port *port,
        if (!pdata)
                return -EINVAL;
 
-       if (rs485->flags & SER_RS485_ENABLED)
+       /* Hardware do not support same RTS level on send and receive */
+       if (!(rs485->flags & SER_RS485_RTS_ON_SEND) ==
+                       !(rs485->flags & SER_RS485_RTS_AFTER_SEND))
+               return -EINVAL;
+
+       if (rs485->flags & SER_RS485_ENABLED) {
                memset(rs485->padding, 0, sizeof(rs485->padding));
-       else
+               config |= RS485_URA;
+       } else {
                memset(rs485, 0, sizeof(*rs485));
+       }
 
        rs485->flags &= SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND |
                        SER_RS485_RTS_AFTER_SEND;
@@ -215,12 +222,6 @@ static int fintek_8250_rs485_config(struct uart_port *port,
                config |= RXW4C_IRA;
        }
 
-       if ((!!(rs485->flags & SER_RS485_RTS_ON_SEND)) ==
-                       (!!(rs485->flags & SER_RS485_RTS_AFTER_SEND)))
-               rs485->flags &= ~SER_RS485_ENABLED;
-       else
-               config |= RS485_URA;
-
        if (rs485->flags & SER_RS485_RTS_ON_SEND)
                config |= RTS_INVERT;