]>
Commit | Line | Data |
---|---|---|
b74db2ac GKH |
1 | From 8c34cb8ddfe808d557b51da983ff10c02793beb2 Mon Sep 17 00:00:00 2001 |
2 | From: Johan Hovold <johan@kernel.org> | |
3 | Date: Thu, 12 Jan 2017 14:56:20 +0100 | |
4 | Subject: USB: serial: quatech2: fix control-message error handling | |
5 | ||
6 | From: Johan Hovold <johan@kernel.org> | |
7 | ||
8 | commit 8c34cb8ddfe808d557b51da983ff10c02793beb2 upstream. | |
9 | ||
10 | Make sure to detect short control-message transfers when fetching | |
11 | modem and line state in open and when retrieving registers. | |
12 | ||
13 | This specifically makes sure that an errno is returned to user space on | |
14 | errors in TIOCMGET instead of a zero bitmask. | |
15 | ||
16 | Also drop the unused getdevice function which also lacked appropriate | |
17 | error handling. | |
18 | ||
19 | Fixes: f7a33e608d9a ("USB: serial: add quatech2 usb to serial driver") | |
20 | Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
21 | Signed-off-by: Johan Hovold <johan@kernel.org> | |
22 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
23 | ||
24 | --- | |
25 | drivers/usb/serial/quatech2.c | 24 +++++++++++++----------- | |
26 | 1 file changed, 13 insertions(+), 11 deletions(-) | |
27 | ||
28 | --- a/drivers/usb/serial/quatech2.c | |
29 | +++ b/drivers/usb/serial/quatech2.c | |
30 | @@ -188,22 +188,22 @@ static inline int qt2_setdevice(struct u | |
31 | } | |
32 | ||
33 | ||
34 | -static inline int qt2_getdevice(struct usb_device *dev, u8 *data) | |
35 | -{ | |
36 | - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
37 | - QT_SET_GET_DEVICE, 0xc0, 0, 0, | |
38 | - data, 3, QT2_USB_TIMEOUT); | |
39 | -} | |
40 | - | |
41 | static inline int qt2_getregister(struct usb_device *dev, | |
42 | u8 uart, | |
43 | u8 reg, | |
44 | u8 *data) | |
45 | { | |
46 | - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
47 | - QT_SET_GET_REGISTER, 0xc0, reg, | |
48 | - uart, data, sizeof(*data), QT2_USB_TIMEOUT); | |
49 | + int ret; | |
50 | ||
51 | + ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
52 | + QT_SET_GET_REGISTER, 0xc0, reg, | |
53 | + uart, data, sizeof(*data), QT2_USB_TIMEOUT); | |
54 | + if (ret < sizeof(*data)) { | |
55 | + if (ret >= 0) | |
56 | + ret = -EIO; | |
57 | + } | |
58 | + | |
59 | + return ret; | |
60 | } | |
61 | ||
62 | static inline int qt2_setregister(struct usb_device *dev, | |
63 | @@ -372,9 +372,11 @@ static int qt2_open(struct tty_struct *t | |
64 | 0xc0, 0, | |
65 | device_port, data, 2, QT2_USB_TIMEOUT); | |
66 | ||
67 | - if (status < 0) { | |
68 | + if (status < 2) { | |
69 | dev_err(&port->dev, "%s - open port failed %i\n", __func__, | |
70 | status); | |
71 | + if (status >= 0) | |
72 | + status = -EIO; | |
73 | kfree(data); | |
74 | return status; | |
75 | } |