Skip to content

Commit cd8db05

Browse files
committed
USB: serial: mos7840: fix control-message error handling
Make sure to detect short transfers when reading a device register. The modem-status handling had sufficient error checks in place, but move handling of short transfers into the register accessor function itself for consistency. Reviewed-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Johan Hovold <[email protected]>
1 parent 0d13036 commit cd8db05

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers/usb/serial/mos7840.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,15 @@ static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
284284
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
285285
MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH,
286286
MOS_WDR_TIMEOUT);
287+
if (ret < VENDOR_READ_LENGTH) {
288+
if (ret >= 0)
289+
ret = -EIO;
290+
goto out;
291+
}
292+
287293
*val = buf[0];
288294
dev_dbg(&port->dev, "%s offset is %x, return val %x\n", __func__, reg, *val);
289-
295+
out:
290296
kfree(buf);
291297
return ret;
292298
}
@@ -352,8 +358,13 @@ static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
352358
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
353359
MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH,
354360
MOS_WDR_TIMEOUT);
361+
if (ret < VENDOR_READ_LENGTH) {
362+
if (ret >= 0)
363+
ret = -EIO;
364+
goto out;
365+
}
355366
*val = buf[0];
356-
367+
out:
357368
kfree(buf);
358369
return ret;
359370
}
@@ -1479,10 +1490,10 @@ static int mos7840_tiocmget(struct tty_struct *tty)
14791490
return -ENODEV;
14801491

14811492
status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1482-
if (status != 1)
1493+
if (status < 0)
14831494
return -EIO;
14841495
status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1485-
if (status != 1)
1496+
if (status < 0)
14861497
return -EIO;
14871498
result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
14881499
| ((mcr & MCR_RTS) ? TIOCM_RTS : 0)

0 commit comments

Comments
 (0)