mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugo Villeneuve <hugo@hugovil.com>
To: Biju <biju.das.au@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	Biju Das <biju.das.jz@bp.renesas.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Thierry Bultel <thierry.bultel.yh@bp.renesas.com>,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault
Date: Wed, 8 Apr 2026 12:30:39 -0400	[thread overview]
Message-ID: <20260408123039.922a75327fd7672df3bd61da@hugovil.com> (raw)
In-Reply-To: <20260408142105.310210-2-biju.das.jz@bp.renesas.com>

Hi Biju,

On Wed,  8 Apr 2026 15:20:58 +0100
Biju <biju.das.au@gmail.com> wrote:

> From: Biju Das <biju.das.jz@bp.renesas.com>
> 
> uart_update_timeout() computes a timeout value by dividing by the baud
> rate. If baud is zero — which can occur when the hardware returns an
> unsupported or invalid rate — this results in a divide-by-zero fault.

baud is returned by uart_get_baud_rate(), so this is not returned
by the hardware?


> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>

Missing Fixes tag?


> ---
> v2:
>  * New patch
> ---
>  drivers/tty/serial/rsci.c   | 3 ++-
>  drivers/tty/serial/sh-sci.c | 3 ++-
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c
> index b00c9e385169..a0858bab0822 100644
> --- a/drivers/tty/serial/rsci.c
> +++ b/drivers/tty/serial/rsci.c
> @@ -286,7 +286,8 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios,
>  	sci_port_enable(s);
>  	uart_port_lock_irqsave(port, &flags);
>  
> -	uart_update_timeout(port, termios->c_cflag, baud);
> +	if (baud)
> +		uart_update_timeout(port, termios->c_cflag, baud);
>  
>  	rsci_serial_out(port, CCR0, ccr0_val);
>  
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 6c819b6b2425..429e89106ee3 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -2805,7 +2805,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
>  
>  	sci_reset(port);
>  
> -	uart_update_timeout(port, termios->c_cflag, baud);
> +	if (baud)
> +		uart_update_timeout(port, termios->c_cflag, baud);

After this patch, have you re-tested if having baud = 0 produces any
other errors? A litle bit later in the same function, there is this
code:

    /* Calculate delay for 2 DMA buffers (4 FIFO). */
    s->rx_frame = (10000 * bits) / (baud / 100);

Does this trigger a division by zero fault?

There is also this:

	if ((srr + 1 == 5) &&
	    (s->type == PORT_SCIFA || s->type == PORT_SCIFB)) {
            ...
		udelay(DIV_ROUND_UP(10 * 1000000, baud));

Can this also trigger a division by zero fault?


>  
>  	/* byte size and parity */
>  	bits = tty_get_frame_size(termios->c_cflag);
> -- 
> 2.43.0
> 
> 


-- 
Hugo Villeneuve

  parent reply	other threads:[~2026-04-08 16:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08 14:20 [PATCH v2 0/2] serial: sh-sci/rsci: Fix divide by zero and clean up baud rate logic Biju
2026-04-08 14:20 ` [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault Biju
2026-04-08 15:39   ` Geert Uytterhoeven
2026-04-08 16:05     ` Biju Das
2026-04-08 16:30   ` Hugo Villeneuve [this message]
2026-04-08 16:35     ` Biju Das
2026-04-08 16:51       ` Hugo Villeneuve
2026-04-08 17:25         ` Biju Das
2026-04-08 18:15           ` Hugo Villeneuve
2026-04-08 19:02             ` Biju Das
2026-04-09  7:40               ` Biju Das
2026-04-09 14:16                 ` Hugo Villeneuve
2026-04-13 10:24           ` Geert Uytterhoeven
2026-04-16 16:31             ` Biju Das
2026-04-08 14:20 ` [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection Biju
2026-04-08 15:45   ` Geert Uytterhoeven
2026-04-08 15:53     ` Geert Uytterhoeven
2026-04-08 16:01       ` Biju Das

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=20260408123039.922a75327fd7672df3bd61da@hugovil.com \
    --to=hugo@hugovil.com \
    --cc=biju.das.au@gmail.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=thierry.bultel.yh@bp.renesas.com \
    --cc=wsa+renesas@sang-engineering.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®