Aw: Re: [PATCH v3 1/9] serial: core: move RS485 configuration tasks from drivers into core

Lino Sanfilippo LinoSanfilippo at gmx.de
Fri Feb 25 02:16:40 PST 2022


Hi,


> On 22. 02. 22, 7:51, Jiri Slaby wrote:
> > On 22. 02. 22, 2:14, Lino Sanfilippo wrote:
> >> Several drivers that support setting the RS485 configuration via 
> >> userspace
> >> implement one or more of the following tasks:
> >>
> >> - in case of an invalid RTS configuration (both RTS after send and RTS on
> >>    send set or both unset) fall back to enable RTS on send and disable 
> >> RTS
> >>    after send
> >>
> >> - nullify the padding field of the returned serial_rs485 struct
> >>
> >> - copy the configuration into the uart port struct
> >>
> >> - limit RTS delays to 100 ms
> >>
> >> Move these tasks into the serial core to make them generic and to provide
> >> a consistent behaviour among all drivers.
> >>
> >> Signed-off-by: Lino Sanfilippo <LinoSanfilippo at gmx.de>
> >> ---
> >>   drivers/tty/serial/serial_core.c | 29 +++++++++++++++++++++++++++++
> >>   1 file changed, 29 insertions(+)
> >>
> >> diff --git a/drivers/tty/serial/serial_core.c 
> >> b/drivers/tty/serial/serial_core.c
> >> index 846192a7b4bf..2b3afe038c1c 100644
> >> --- a/drivers/tty/serial/serial_core.c
> >> +++ b/drivers/tty/serial/serial_core.c
> >> @@ -42,6 +42,11 @@ static struct lock_class_key port_lock_key;
> >>   #define HIGH_BITS_OFFSET    ((sizeof(long)-sizeof(int))*8)
> >> +/*
> >> + * Max time with active RTS before/after data is sent.
> >> + */
> >> +#define RS485_MAX_RTS_DELAY    100 /* msecs */
> >> +
> >>   static void uart_change_speed(struct tty_struct *tty, struct 
> >> uart_state *state,
> >>                       struct ktermios *old_termios);
> >>   static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
> >> @@ -1282,8 +1287,32 @@ static int uart_set_rs485_config(struct 
> >> uart_port *port,
> >>       if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
> >>           return -EFAULT;
> >> +    /* pick sane settings if the user hasn't */
> >> +    if (!(rs485.flags & SER_RS485_RTS_ON_SEND) ==
> >> +        !(rs485.flags & SER_RS485_RTS_AFTER_SEND)) {
> >> +        pr_warn("invalid RTS setting, using RTS_ON_SEND instead\n");
> > 
> > Can't we have a device prefix here, so that everyone knows what device 
> > is affected? Without that, it's not that useful. At least port->name & 
> > port->line could be printed. The uart core uses dev_* prints, but prints 
> > also line as uport->dev can be NULL sometimes.
> 
> And this comes from userspace, so should be ratelimited.
> 

Right, ratelimiting makes sense here. I will change it as suggested in the next patch version.
Thanks a lot for the review.

Regards,
Lino




More information about the linux-arm-kernel mailing list