Skip to content

Commit ea04bd7

Browse files
jhovoldgregkh
authored andcommitted
USB: serial: quatech2: fix control-message error handling
commit 8c34cb8ddfe808d557b51da983ff10c02793beb2 upstream. Make sure to detect short control-message transfers when fetching modem and line state in open and when retrieving registers. This specifically makes sure that an errno is returned to user space on errors in TIOCMGET instead of a zero bitmask. Also drop the unused getdevice function which also lacked appropriate error handling. Fixes: f7a33e6 ("USB: serial: add quatech2 usb to serial driver") Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f15ca92 commit ea04bd7

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

drivers/usb/serial/quatech2.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,22 @@ static inline int qt2_setdevice(struct usb_device *dev, u8 *data)
188188
}
189189

190190

191-
static inline int qt2_getdevice(struct usb_device *dev, u8 *data)
192-
{
193-
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
194-
QT_SET_GET_DEVICE, 0xc0, 0, 0,
195-
data, 3, QT2_USB_TIMEOUT);
196-
}
197-
198191
static inline int qt2_getregister(struct usb_device *dev,
199192
u8 uart,
200193
u8 reg,
201194
u8 *data)
202195
{
203-
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
204-
QT_SET_GET_REGISTER, 0xc0, reg,
205-
uart, data, sizeof(*data), QT2_USB_TIMEOUT);
196+
int ret;
197+
198+
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
199+
QT_SET_GET_REGISTER, 0xc0, reg,
200+
uart, data, sizeof(*data), QT2_USB_TIMEOUT);
201+
if (ret < sizeof(*data)) {
202+
if (ret >= 0)
203+
ret = -EIO;
204+
}
206205

206+
return ret;
207207
}
208208

209209
static inline int qt2_setregister(struct usb_device *dev,
@@ -372,9 +372,11 @@ static int qt2_open(struct tty_struct *tty, struct usb_serial_port *port)
372372
0xc0, 0,
373373
device_port, data, 2, QT2_USB_TIMEOUT);
374374

375-
if (status < 0) {
375+
if (status < 2) {
376376
dev_err(&port->dev, "%s - open port failed %i\n", __func__,
377377
status);
378+
if (status >= 0)
379+
status = -EIO;
378380
kfree(data);
379381
return status;
380382
}

0 commit comments

Comments
 (0)