All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Hui Peng <benquike@gmail.com>
Cc: "Jiri Slaby" <jirislaby@kernel.org>,
	"John Ogness" <john.ogness@linutronix.de>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v7 1/2] serial: core: fix baud rate fallback in uart_get_baud_rate()
Date: Thu, 1 Oct 2026 10:54:28 +0200	[thread overview]
Message-ID: <2026100156-watch-balsamic-32db@gregkh> (raw)
In-Reply-To: <20260930125901.778868-2-benquike@gmail.com>

On Wed, Sep 30, 2026 at 12:59:00PM +0000, Hui Peng wrote:
> When uart_get_baud_rate() is called with a baud rate exceeding the port's
> maximum supported speed (port->uartclk / 16), it clips baud to [min,
> max - 1] and encodes it into termios via tty_termios_encode_baud_rate().
> 
> However, because the loop bound is for (try = 0; try < 2; try++), the
> loop terminates immediately after try == 1 without re-evaluating

But try == 1 should keep the loop going as it is < 2, right?  What am I
missing here?  Do I need more coffee?

> baud = tty_termios_baud_rate(termios) for the clipped rate, hitting
> WARN_ON(1) and returning 0, which then triggers a fatal divide-by-zero
> (Oops: divide error) in uart_get_divisor():
> 
>   WARNING: drivers/tty/serial/serial_core.c:548 at uart_get_baud_rate+0x136/0x260
>   [ ... ]
>   divide error: 0000 [#1] PREEMPT SMP KASAN
> 
> Increase the retry count in uart_get_baud_rate() from 2 to 3 iterations so
> that clipped baud rates are re-evaluated in the third iteration.

What is the magic 2 here, and why turning it into a magic 3 somehow fix
things?

thanks,

greg k-h

  reply	other threads:[~2026-10-01  8:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 12:58 [PATCH v7 0/2] serial: core: fix baud rate fallback loop and baud_base overflow Hui Peng
2026-09-30 12:59 ` [PATCH v7 1/2] serial: core: fix baud rate fallback in uart_get_baud_rate() Hui Peng
2026-10-01  8:54   ` Greg Kroah-Hartman [this message]
2026-10-01  9:46     ` Ilpo Järvinen
2026-10-06 15:29       ` Hugo Villeneuve
2026-10-07 10:38         ` Ilpo Järvinen
2026-10-07 17:06           ` Hugo Villeneuve
2026-10-07 20:09             ` Ilpo Järvinen
2026-10-07 20:27               ` Hugo Villeneuve
2026-09-30 12:59 ` [PATCH v7 2/2] serial: core: reject baud_base values that overflow port->uartclk in uart_set_info() Hui Peng
2026-09-30 14:09   ` Andy Shevchenko
2026-10-01  8:55   ` Greg Kroah-Hartman
2026-10-06 15:36   ` Hugo Villeneuve
2026-10-01  8:50 ` [PATCH v7 0/2] serial: core: fix baud rate fallback loop and baud_base overflow Greg Kroah-Hartman

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=2026100156-watch-balsamic-32db@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=benquike@gmail.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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 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.