linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ricardo Ribalda Delgado <ribalda@kernel.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-serial <linux-serial@vger.kernel.org>,
	Lukas Wunner <lukas@wunner.de>, Jiri Slaby <jirislaby@kernel.org>,
	"Ji-Ze Hong (Peter Hong)" <hpeter@gmail.com>
Subject: Re: [PATCH] serial: 8250_fintek: Check SER_RS485_RTS_* only with RS485
Date: Mon, 16 May 2022 15:01:35 +0200	[thread overview]
Message-ID: <CAPybu_0s86DENGRmcrhtsCttpmofGV=qsMeXFcs6=FS9dKVgew@mail.gmail.com> (raw)
In-Reply-To: <035c738-8ea5-8b17-b1d7-84a7b3aeaa51@linux.intel.com>

On Fri, May 13, 2022 at 3:47 PM Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
>
> SER_RS485_RTS_ON_SEND and SER_RS485_RTS_AFTER_SEND relate to behavior
> within RS485 operation. The driver checks if they have the same value
> which is not possible to realize with the hardware. The check is taken
> regardless of SER_RS485_ENABLED flag and -EINVAL is returned when the
> check fails, which creates problems.
>
> This check makes it unnecessarily complicated to turn RS485 mode off as
> simple zeroed serial_rs485 struct will trigger that equal values check.
> In addition, the driver itself memsets its rs485 structure to zero when
> RS485 is disabled but if userspace would try to make an TIOCSRS485
> ioctl() call with the very same struct, it would end up failing with
> -EINVAL which doesn't make much sense.
>
> Resolve the problem by moving the check inside SER_RS485_ENABLED block.
>
> Fixes: 7ecc77011c6f ("serial: 8250_fintek: Return -EINVAL on invalid configuration")
> Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
>
> ---
>  drivers/tty/serial/8250/8250_fintek.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c
> index 251f0018ae8c..dba5950b8d0e 100644
> --- a/drivers/tty/serial/8250/8250_fintek.c
> +++ b/drivers/tty/serial/8250/8250_fintek.c
> @@ -200,12 +200,12 @@ static int fintek_8250_rs485_config(struct uart_port *port,
>         if (!pdata)
>                 return -EINVAL;
>
> -       /* 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) {
> +               /* 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;
>                 memset(rs485->padding, 0, sizeof(rs485->padding));
>                 config |= RS485_URA;
>         } else {
>
> --
> tg: (4419da5d5d4b..) fix/8250-fintek-rts-check (depends on: tty-next)

      reply	other threads:[~2022-05-16 13:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13 13:46 [PATCH] serial: 8250_fintek: Check SER_RS485_RTS_* only with RS485 Ilpo Järvinen
2022-05-16 13:01 ` Ricardo Ribalda Delgado [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPybu_0s86DENGRmcrhtsCttpmofGV=qsMeXFcs6=FS9dKVgew@mail.gmail.com' \
    --to=ribalda@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpeter@gmail.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=lukas@wunner.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).