Re: [PATCH v4 1/5] serial: core: tidy invalid baudrate handling in uart_get_baud_rate

From: Max Filippov
Date: Fri Sep 29 2023 - 15:26:47 EST


On Thu, Sep 28, 2023 at 11:34 PM Ilpo Järvinen
<ilpo.jarvinen@xxxxxxxxxxxxxxx> wrote:
> While looking into this, I found this old commit:
>
> commit 16ae2a877bf4179737921235e85ceffd7b79354f
> Author: Alan Cox <alan@xxxxxxxxxxxxxxx>
> Date: Mon Jan 4 16:26:21 2010 +0000
>
> serial: Fix crash if the minimum rate of the device is > 9600 baud
>
> In that situation if the old rate is invalid and the new rate is invalid
> and the chip cannot do 9600 baud we report zero, which makes all the
> drivers explode.
>
> Instead force the rate based on min/max
>
> But for some reason it does not work as advertized here? What is the exact
> cause for that?

In my case I see that tty_termios_encode_baud_rate() is called with
ibaud == obaud == 9769, but it finds the closest rate 9600, which is
within 2% of the actual minimum, but is outside the min/max range
supported by the hardware.

> Is something wrong with how min/max have that +1/-1 there or what?

--
Thanks.
-- Max