Skip to content

Commit aece86f

Browse files
jhovoldgregkh
authored andcommitted
USB: serial: ssu100: fix control-message error handling
commit 1eac5c244f705182d1552a53e2f74e2775ed95d6 upstream. Make sure to detect short control-message transfers rather than continue with zero-initialised data when retrieving modem status and during device initialisation. Fixes: 52af954 ("USB: add USB serial ssu100 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 a655b21 commit aece86f

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

drivers/usb/serial/ssu100.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,35 @@ static inline int ssu100_setdevice(struct usb_device *dev, u8 *data)
8080

8181
static inline int ssu100_getdevice(struct usb_device *dev, u8 *data)
8282
{
83-
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
84-
QT_SET_GET_DEVICE, 0xc0, 0, 0,
85-
data, 3, 300);
83+
int ret;
84+
85+
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
86+
QT_SET_GET_DEVICE, 0xc0, 0, 0,
87+
data, 3, 300);
88+
if (ret < 3) {
89+
if (ret >= 0)
90+
ret = -EIO;
91+
}
92+
93+
return ret;
8694
}
8795

8896
static inline int ssu100_getregister(struct usb_device *dev,
8997
unsigned short uart,
9098
unsigned short reg,
9199
u8 *data)
92100
{
93-
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
94-
QT_SET_GET_REGISTER, 0xc0, reg,
95-
uart, data, sizeof(*data), 300);
101+
int ret;
102+
103+
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
104+
QT_SET_GET_REGISTER, 0xc0, reg,
105+
uart, data, sizeof(*data), 300);
106+
if (ret < sizeof(*data)) {
107+
if (ret >= 0)
108+
ret = -EIO;
109+
}
96110

111+
return ret;
97112
}
98113

99114

@@ -289,8 +304,10 @@ static int ssu100_open(struct tty_struct *tty, struct usb_serial_port *port)
289304
QT_OPEN_CLOSE_CHANNEL,
290305
QT_TRANSFER_IN, 0x01,
291306
0, data, 2, 300);
292-
if (result < 0) {
307+
if (result < 2) {
293308
dev_dbg(&port->dev, "%s - open failed %i\n", __func__, result);
309+
if (result >= 0)
310+
result = -EIO;
294311
kfree(data);
295312
return result;
296313
}

0 commit comments

Comments
 (0)