]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.9.28/usb-serial-quatech2-fix-control-message-error-handling.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.9.28 / usb-serial-quatech2-fix-control-message-error-handling.patch
CommitLineData
b74db2ac
GKH
1From 8c34cb8ddfe808d557b51da983ff10c02793beb2 Mon Sep 17 00:00:00 2001
2From: Johan Hovold <johan@kernel.org>
3Date: Thu, 12 Jan 2017 14:56:20 +0100
4Subject: USB: serial: quatech2: fix control-message error handling
5
6From: Johan Hovold <johan@kernel.org>
7
8commit 8c34cb8ddfe808d557b51da983ff10c02793beb2 upstream.
9
10Make sure to detect short control-message transfers when fetching
11modem and line state in open and when retrieving registers.
12
13This specifically makes sure that an errno is returned to user space on
14errors in TIOCMGET instead of a zero bitmask.
15
16Also drop the unused getdevice function which also lacked appropriate
17error handling.
18
19Fixes: f7a33e608d9a ("USB: serial: add quatech2 usb to serial driver")
20Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21Signed-off-by: Johan Hovold <johan@kernel.org>
22Signed-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 }