]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
serial: core: prevent division by zero by always returning non-zero baud rate
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Fri, 10 Apr 2026 15:20:13 +0000 (11:20 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 11 May 2026 15:19:52 +0000 (17:19 +0200)
commit091ea8e5d34e1dca5d8f30127173b949e3f803ce
treec9c09e1c33c9c0b4481fb8796a670c193811312f
parent1097aedec77674fe4f08f40b3f0bac26ea437fc0
serial: core: prevent division by zero by always returning non-zero baud rate

If a device has a minimum baud rate > 9600 bauds, and a new termios baud
rate of 0 (hang up) is requested, uart_get_baud_rate() will return 0.
Most drivers do not check this return value and call uart_update_timeout()
with this zero baud rate, which will trigger a "Division by zero in kernel"
fault:

  stty -F /dev/ttySC0 0

  Division by zero in kernel.
  ...

Fix by returning the larger of 9600 or min for the B0 case. This now
ensures that a non-zero baud rate is returned, and greatly simplifies the
code.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://patch.msgid.link/20260410152022.2146488-6-hugo@hugovil.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/serial_core.c