All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Revert "serial: 8250: Fix reporting real baudrate value in c_ospeed field"
@ 2021-10-07 13:31 Johan Hovold
  2021-10-07 14:21 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2021-10-07 13:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Jiri Slaby, linux-serial, linux-kernel, Johan Hovold, Pali Rohár

This reverts commit 32262e2e429cdb31f9e957e997d53458762931b7.

The commit in question claims to determine the inverse of
serial8250_get_divisor() but failed to notice that some drivers override
the default implementation using a get_divisor() callback.

This means that the computed line-speed values can be completely wrong
and results in regular TCSETS requests failing (the incorrect values
would also be passed to any overridden set_divisor() callback).

Similarly, it also failed to honour the old (deprecated) ASYNC_SPD_FLAGS
and would break applications relying on those when re-encoding the
actual line speed.

There are also at least two quirks, UART_BUG_QUOT and an OMAP1510
workaround, which were happily ignored and that are now broken.

Finally, even if the offending commit were to be implemented correctly,
this is a new feature and not something which should be backported to
stable.

Cc: Pali Rohár <pali@kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 17 -----------------
 1 file changed, 17 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index dc6900b2daa8..66374704747e 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2584,19 +2584,6 @@ static unsigned int serial8250_get_divisor(struct uart_port *port,
 	return serial8250_do_get_divisor(port, baud, frac);
 }
 
-static unsigned int serial8250_compute_baud_rate(struct uart_port *port,
-						 unsigned int quot)
-{
-	if ((port->flags & UPF_MAGIC_MULTIPLIER) && quot == 0x8001)
-		return port->uartclk / 4;
-	else if ((port->flags & UPF_MAGIC_MULTIPLIER) && quot == 0x8002)
-		return port->uartclk / 8;
-	else if (port->type == PORT_NPCM)
-		return DIV_ROUND_CLOSEST(port->uartclk - 2 * (quot + 2), 16 * (quot + 2));
-	else
-		return DIV_ROUND_CLOSEST(port->uartclk, 16 * quot);
-}
-
 static unsigned char serial8250_compute_lcr(struct uart_8250_port *up,
 					    tcflag_t c_cflag)
 {
@@ -2727,14 +2714,11 @@ void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk)
 
 	baud = serial8250_get_baud_rate(port, termios, NULL);
 	quot = serial8250_get_divisor(port, baud, &frac);
-	baud = serial8250_compute_baud_rate(port, quot);
 
 	serial8250_rpm_get(up);
 	spin_lock_irqsave(&port->lock, flags);
 
 	uart_update_timeout(port, termios->c_cflag, baud);
-	if (tty_termios_baud_rate(termios))
-		tty_termios_encode_baud_rate(termios, baud, baud);
 
 	serial8250_set_divisor(port, baud, quot, frac);
 	serial_port_out(port, UART_LCR, up->lcr);
@@ -2766,7 +2750,6 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 
 	baud = serial8250_get_baud_rate(port, termios, old);
 	quot = serial8250_get_divisor(port, baud, &frac);
-	baud = serial8250_compute_baud_rate(port, quot);
 
 	/*
 	 * Ok, we're now changing the port state.  Do it with
-- 
2.32.0


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

* Re: [PATCH] Revert "serial: 8250: Fix reporting real baudrate value in c_ospeed field"
  2021-10-07 13:31 [PATCH] Revert "serial: 8250: Fix reporting real baudrate value in c_ospeed field" Johan Hovold
@ 2021-10-07 14:21 ` Greg Kroah-Hartman
  2021-10-07 14:40   ` Pali Rohár
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-10-07 14:21 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Jiri Slaby, linux-serial, linux-kernel, Pali Rohár

On Thu, Oct 07, 2021 at 03:31:46PM +0200, Johan Hovold wrote:
> This reverts commit 32262e2e429cdb31f9e957e997d53458762931b7.
> 
> The commit in question claims to determine the inverse of
> serial8250_get_divisor() but failed to notice that some drivers override
> the default implementation using a get_divisor() callback.
> 
> This means that the computed line-speed values can be completely wrong
> and results in regular TCSETS requests failing (the incorrect values
> would also be passed to any overridden set_divisor() callback).
> 
> Similarly, it also failed to honour the old (deprecated) ASYNC_SPD_FLAGS
> and would break applications relying on those when re-encoding the
> actual line speed.
> 
> There are also at least two quirks, UART_BUG_QUOT and an OMAP1510
> workaround, which were happily ignored and that are now broken.
> 
> Finally, even if the offending commit were to be implemented correctly,
> this is a new feature and not something which should be backported to
> stable.
> 
> Cc: Pali Rohár <pali@kernel.org>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 17 -----------------
>  1 file changed, 17 deletions(-)

Argh, sorry I missed this, good catch.  I'll go queue this up now,
thanks.

greg k-h

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

* Re: [PATCH] Revert "serial: 8250: Fix reporting real baudrate value in c_ospeed field"
  2021-10-07 14:21 ` Greg Kroah-Hartman
@ 2021-10-07 14:40   ` Pali Rohár
  0 siblings, 0 replies; 3+ messages in thread
From: Pali Rohár @ 2021-10-07 14:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Johan Hovold, Jiri Slaby, linux-serial, linux-kernel

On Thursday 07 October 2021 16:21:30 Greg Kroah-Hartman wrote:
> On Thu, Oct 07, 2021 at 03:31:46PM +0200, Johan Hovold wrote:
> > This reverts commit 32262e2e429cdb31f9e957e997d53458762931b7.
> > 
> > The commit in question claims to determine the inverse of
> > serial8250_get_divisor() but failed to notice that some drivers override
> > the default implementation using a get_divisor() callback.
> > 
> > This means that the computed line-speed values can be completely wrong
> > and results in regular TCSETS requests failing (the incorrect values
> > would also be passed to any overridden set_divisor() callback).
> > 
> > Similarly, it also failed to honour the old (deprecated) ASYNC_SPD_FLAGS
> > and would break applications relying on those when re-encoding the
> > actual line speed.
> > 
> > There are also at least two quirks, UART_BUG_QUOT and an OMAP1510
> > workaround, which were happily ignored and that are now broken.
> > 
> > Finally, even if the offending commit were to be implemented correctly,
> > this is a new feature and not something which should be backported to
> > stable.
> > 
> > Cc: Pali Rohár <pali@kernel.org>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> >  drivers/tty/serial/8250/8250_port.c | 17 -----------------
> >  1 file changed, 17 deletions(-)
> 
> Argh, sorry I missed this, good catch.  I'll go queue this up now,
> thanks.
> 
> greg k-h

I was waiting for a reply in discussion for this patch...
https://lore.kernel.org/linux-serial/20210927093704.19768-1-pali@kernel.org/t/#u

There was no reply, so I was surprised it was taken without any
reaction. I was really in impression that patch is waiting.

So sorry for that.

Johan, could you write comments below original patch, so discussion is
not on two places? I would really like to fix this issue because
c_ospeed contains incorrect value.

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

end of thread, other threads:[~2021-10-07 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-07 13:31 [PATCH] Revert "serial: 8250: Fix reporting real baudrate value in c_ospeed field" Johan Hovold
2021-10-07 14:21 ` Greg Kroah-Hartman
2021-10-07 14:40   ` Pali Rohár

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.