Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH] serial: amba-pl011: Fix divide by zero in pl011_console_get_options()
@ 2026-11-11  9:23 Dan Carpenter
  2026-11-11  9:29 ` sashiko-bot
  2026-11-12  8:08 ` Nicolai Buchwitz
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2026-11-11  9:23 UTC (permalink / raw)
  To: Russell King
  Cc: Greg Kroah-Hartman, Jiri Slaby, Kartik Rajput, Nicolai Buchwitz,
	Fan Wu, Frank Li, Karl Mehltretter, Stefan Dösinger,
	linux-serial

When you boot QEMU with -kernel and don't set a baud rate the ibrd and
fbrd values are zero and so clkdiv is also zero.  It results in a divide
by zero.  Most of the time people don't notice because on
qemu-system-arm64 when you divide by zero the result is zero and
everything works.  However, if you enable UBSAN, then the divide by zero
leads to a crash and the boot fails.

Return early when clkdev is zero.  This leaves the baud rate set to its
default value of 38400.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@cryspen.com>
---
 drivers/tty/serial/amba-pl011.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 7b1f99395f6c..a630d4751628 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -2600,6 +2600,9 @@ static void pl011_console_get_options(struct uart_amba_port *uap, int *baud,
 		clkdiv = 64 * ibrd + fbrd;
 	}
 
+	if (!clkdiv)
+		return;
+
 	*baud = uap->port.uartclk * 4 / clkdiv;
 
 	if (uap->vendor->oversampling &&
-- 
2.53.0


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

* Re: [PATCH] serial: amba-pl011: Fix divide by zero in pl011_console_get_options()
  2026-11-11  9:23 [PATCH] serial: amba-pl011: Fix divide by zero in pl011_console_get_options() Dan Carpenter
@ 2026-11-11  9:29 ` sashiko-bot
  2026-11-12  8:08 ` Nicolai Buchwitz
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-11  9:29 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-serial

> When you boot QEMU with -kernel and don't set a baud rate the ibrd and
> fbrd values are zero and so clkdiv is also zero.  It results in a divide
> by zero.  Most of the time people don't notice because on
> qemu-system-arm64 when you divide by zero the result is zero and
> everything works.  However, if you enable UBSAN, then the divide by zero
> leads to a crash and the boot fails.
> 
> Return early when clkdev is zero.  This leaves the baud rate set to its
> default value of 38400.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dan Carpenter <dan@cryspen.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/6fdea544b2fb8f4226e296a952331cd42684474d.1794315353.git.dan@cryspen.com?part=1


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

* Re: [PATCH] serial: amba-pl011: Fix divide by zero in pl011_console_get_options()
  2026-11-11  9:23 [PATCH] serial: amba-pl011: Fix divide by zero in pl011_console_get_options() Dan Carpenter
  2026-11-11  9:29 ` sashiko-bot
@ 2026-11-12  8:08 ` Nicolai Buchwitz
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolai Buchwitz @ 2026-11-12  8:08 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Russell King, Greg Kroah-Hartman, Jiri Slaby, Kartik Rajput,
	Fan Wu, Frank Li, Karl Mehltretter, Stefan Dösinger,
	linux-serial

Hi Dan

On 11.11.2026 10:23, Dan Carpenter wrote:
> When you boot QEMU with -kernel and don't set a baud rate the ibrd and
> fbrd values are zero and so clkdiv is also zero.  It results in a 
> divide
> by zero.  Most of the time people don't notice because on
> qemu-system-arm64 when you divide by zero the result is zero and
> everything works.  However, if you enable UBSAN, then the divide by 
> zero
> leads to a crash and the boot fails.
> 
> Return early when clkdev is zero.  This leaves the baud rate set to its

nit: clkdiv

> default value of 38400.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dan Carpenter <dan@cryspen.com>

> [...]

Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>

Thanks,
Nicolai

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

end of thread, other threads:[~2026-11-12  8:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  9:23 [PATCH] serial: amba-pl011: Fix divide by zero in pl011_console_get_options() Dan Carpenter
2026-11-11  9:29 ` sashiko-bot
2026-11-12  8:08 ` Nicolai Buchwitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox