Skip to content

Commit 188c9c2

Browse files
committed
USB: serial: f81534: fix division by zero on line-speed change
The driver leaves the line speed unchanged in case a requested speed is not supported. Make sure to handle the case where the current speed is B0 (hangup) without dividing by zero when determining the clock source. Fixes: 3aacac0 ("USB: serial: f81534: add high baud rate support") Cc: stable@vger.kernel.org # 4.16 Cc: Ji-Ze Hong (Peter Hong) <hpeter@gmail.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
1 parent a08ca6e commit 188c9c2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/usb/serial/f81534.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,6 @@ static int f81534_submit_writer(struct usb_serial_port *port, gfp_t mem_flags)
536536

537537
static u32 f81534_calc_baud_divisor(u32 baudrate, u32 clockrate)
538538
{
539-
if (!baudrate)
540-
return 0;
541-
542539
/* Round to nearest divisor */
543540
return DIV_ROUND_CLOSEST(clockrate, baudrate);
544541
}
@@ -568,9 +565,14 @@ static int f81534_set_port_config(struct usb_serial_port *port,
568565
u32 baud_list[] = {baudrate, old_baudrate, F81534_DEFAULT_BAUD_RATE};
569566

570567
for (i = 0; i < ARRAY_SIZE(baud_list); ++i) {
571-
idx = f81534_find_clk(baud_list[i]);
568+
baudrate = baud_list[i];
569+
if (baudrate == 0) {
570+
tty_encode_baud_rate(tty, 0, 0);
571+
return 0;
572+
}
573+
574+
idx = f81534_find_clk(baudrate);
572575
if (idx >= 0) {
573-
baudrate = baud_list[i];
574576
tty_encode_baud_rate(tty, baudrate, baudrate);
575577
break;
576578
}

0 commit comments

Comments
 (0)