serial: Fix crash if the minimum rate of the device is > 9600 baud

In that situation if the old rate is invalid and the new rate is invalid
and the chip cannot do 9600 baud we report zero, which makes all the
drivers explode.

Instead force the rate based on min/max

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by Alan Cox and committed by Greg Kroah-Hartman 16ae2a87 4547be78

+12 -5
+12 -5
drivers/serial/serial_core.c
··· 385 } 386 387 /* 388 - * As a last resort, if the quotient is zero, 389 - * default to 9600 bps 390 */ 391 - if (!hung_up) 392 - tty_termios_encode_baud_rate(termios, 9600, 9600); 393 } 394 - 395 return 0; 396 } 397
··· 385 } 386 387 /* 388 + * As a last resort, if the range cannot be met then clip to 389 + * the nearest chip supported rate. 390 */ 391 + if (!hung_up) { 392 + if (baud <= min) 393 + tty_termios_encode_baud_rate(termios, 394 + min + 1, min + 1); 395 + else 396 + tty_termios_encode_baud_rate(termios, 397 + max - 1, max - 1); 398 + } 399 } 400 + /* Should never happen */ 401 + WARN_ON(1); 402 return 0; 403 } 404