serial: atmel: fix incorrect baudrate setup

Message ID 20230109070200.200181-1-t.schramm@manjaro.org
State New
Headers
Series serial: atmel: fix incorrect baudrate setup |

Commit Message

Tobias Schramm Jan. 9, 2023, 7:02 a.m. UTC
  Commit ba47f97a18f2 ("serial: core: remove baud_rates when serial console
setup") changed uart_set_options to select the correct baudrate
configuration based on the absolute error between requested baudrate and
available standard baudrate settings.
Prior to that commit the baudrate was selected based on which predefined
standard baudrate did not exceed the requested baudrate.
This change of selection logic was never reflected in the atmel serial
driver. Thus the comment left in the atmel serial driver is no longer
accurate.
Additionally the manual rounding up described in that comment and applied
via (quot - 1) requests an incorrect baudrate. Since uart_set_options uses
tty_termios_encode_baud_rate to determine the appropriate baudrate flags
this can cause baudrate selection to fail entirely because
tty_termios_encode_baud_rate will only select a baudrate if relative error
between requested and selected baudrate does not exceed +/-2%.
Fix that by requesting actual, exact baudrate used by the serial.

Signed-off-by: Tobias Schramm <t.schramm@manjaro.org>
---
 drivers/tty/serial/atmel_serial.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
  

Comments

Greg KH Jan. 9, 2023, 7:07 a.m. UTC | #1
On Mon, Jan 09, 2023 at 08:02:00AM +0100, Tobias Schramm wrote:
> Commit ba47f97a18f2 ("serial: core: remove baud_rates when serial console
> setup") changed uart_set_options to select the correct baudrate
> configuration based on the absolute error between requested baudrate and
> available standard baudrate settings.
> Prior to that commit the baudrate was selected based on which predefined
> standard baudrate did not exceed the requested baudrate.
> This change of selection logic was never reflected in the atmel serial
> driver. Thus the comment left in the atmel serial driver is no longer
> accurate.
> Additionally the manual rounding up described in that comment and applied
> via (quot - 1) requests an incorrect baudrate. Since uart_set_options uses
> tty_termios_encode_baud_rate to determine the appropriate baudrate flags
> this can cause baudrate selection to fail entirely because
> tty_termios_encode_baud_rate will only select a baudrate if relative error
> between requested and selected baudrate does not exceed +/-2%.
> Fix that by requesting actual, exact baudrate used by the serial.
> 
> Signed-off-by: Tobias Schramm <t.schramm@manjaro.org>
> ---

What commit id does this fix?  Please list that as a the "Fixes:" tag.

Also, does this need to go to older/stable kernels?

thanks,

greg k-h
  
Tobias Schramm Jan. 9, 2023, 7:22 a.m. UTC | #2
Am 09.01.23 um 08:07 schrieb Greg Kroah-Hartman:
> On Mon, Jan 09, 2023 at 08:02:00AM +0100, Tobias Schramm wrote:
>> Commit ba47f97a18f2 ("serial: core: remove baud_rates when serial console
>> setup") changed uart_set_options to select the correct baudrate
>> configuration based on the absolute error between requested baudrate and
>> available standard baudrate settings.
>> Prior to that commit the baudrate was selected based on which predefined
>> standard baudrate did not exceed the requested baudrate.
>> This change of selection logic was never reflected in the atmel serial
>> driver. Thus the comment left in the atmel serial driver is no longer
>> accurate.
>> Additionally the manual rounding up described in that comment and applied
>> via (quot - 1) requests an incorrect baudrate. Since uart_set_options uses
>> tty_termios_encode_baud_rate to determine the appropriate baudrate flags
>> this can cause baudrate selection to fail entirely because
>> tty_termios_encode_baud_rate will only select a baudrate if relative error
>> between requested and selected baudrate does not exceed +/-2%.
>> Fix that by requesting actual, exact baudrate used by the serial.
>>
>> Signed-off-by: Tobias Schramm <t.schramm@manjaro.org>
>> ---
> What commit id does this fix?  Please list that as a the "Fixes:" tag.

Commit ba47f97a18f2 ("serial: core: remove baud_rates when serial console
setup") is the one that breaks the assumptions made in the driver.
I'll send a v2 and include that.

>
> Also, does this need to go to older/stable kernels?
Yep,  this should go to older kernels as a fix, too.
>
> thanks,
>
> greg k-h
  

Patch

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index f1c06e12efa0..9cd7479b03c0 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -2657,13 +2657,7 @@  static void __init atmel_console_get_options(struct uart_port *port, int *baud,
 	else if (mr == ATMEL_US_PAR_ODD)
 		*parity = 'o';
 
-	/*
-	 * The serial core only rounds down when matching this to a
-	 * supported baud rate. Make sure we don't end up slightly
-	 * lower than one of those, as it would make us fall through
-	 * to a much lower baud rate than we really want.
-	 */
-	*baud = port->uartclk / (16 * (quot - 1));
+	*baud = port->uartclk / (16 * quot);
 }
 
 static int __init atmel_console_setup(struct console *co, char *options)