Skip to contentSkip to conversation

USB: serial: mct_u232: fix big-endian baud-rate handling

PATCH In review Johan Hovold 2 participants 3 messages May 11, 2017 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Johan Hovold

author maintainer
#1 lore raw

PATCH 2/3 USB: serial: mct_u232: fix big-endian baud-rate handling

Drop erroneous cpu_to_le32 when setting the baud rate, something which corrupted the divisor on big-endian hosts.

Found using sparse:

warning: incorrect type in argument 1 (different base types)
expected unsigned int [unsigned] [usertype] val got restricted __le32 [usertype] <noident>

Fixes af2ac1a091bc ("USB: serial mct_usb232: move DMA buffers to heap")
Cc stable <[email protected]> # 2.6.34
Cc Pete Zaitcev <[email protected]>
---
 drivers/usb/serial/mct_u232.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/serial/mct_u232.c +1 -1
index edbc81f205c2..70f346f1aa86 100644
@@ -189,7 +189,7 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty,
 		return -ENOMEM;
 
 	divisor = mct_u232_calculate_baud_rate(serial, value, &speed);
-	put_unaligned_le32(cpu_to_le32(divisor), buf);
+	put_unaligned_le32(divisor, buf);
 	rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
 				MCT_U232_SET_BAUD_RATE_REQUEST,
 				MCT_U232_SET_REQUEST_TYPE,
Signature · 1 line
2.13.0
Acked-by on v1 2/3
#2 lore raw

drivers/usb/serial/mct_u232.c static int mct_u232_set_baud_rate(struct tty_struct *tty, · line 191

Quoted 9 lines · On Thu, 11 May 2017 11:41:20 +0200 Johan Hovold <[email protected]> wrote:

Drop erroneous cpu_to_le32 when setting the baud rate, something which corrupted the divisor on big-endian hosts.

+++ b/drivers/usb/serial/mct_u232.c

drivers/usb/serial/mct_u232.c +1 -1
@@ -189,7 +189,7 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty,
 	divisor = mct_u232_calculate_baud_rate(serial, value, &speed);
-	put_unaligned_le32(cpu_to_le32(divisor), buf);
+	put_unaligned_le32(divisor, buf);
 	rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),

-- Pete

author maintainer
#3 lore raw

PATCH 3/3 USB: serial: io_ti: fix div-by-zero in set_termios

In reply to a message not in the archive

Fix a division-by-zero in set_termios when debugging is enabled and a high-enough speed has been requested so that the divisor value becomes zero.

Instead of just fixing the offending debug statement, cap the baud rate at the base as a zero divisor value also appears to crash the firmware.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc stable <[email protected]> # 2.6.12
---
 drivers/usb/serial/io_ti.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/serial/io_ti.c +4 -1
index 87798e625d6c..6cefb9cb133d 100644
@@ -2336,8 +2336,11 @@ static void change_port_settings(struct tty_struct *tty,
 	if (!baud) {
 		/* pick a default, any default... */
 		baud = 9600;
-	} else
+	} else {
+		/* Avoid a zero divisor. */
+		baud = min(baud, 461550);
 		tty_encode_baud_rate(tty, baud, baud);
+	}
 
 	edge_port->baud_rate = baud;
 	config->wBaudRate = (__u16)((461550L + baud/2) / baud);
Signature · 1 line
2.13.0