]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/media-smsusb-better-handle-optional-alignment.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.19 / media-smsusb-better-handle-optional-alignment.patch
1 From a47686636d84eaec5c9c6e84bd5f96bed34d526d Mon Sep 17 00:00:00 2001
2 From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
3 Date: Fri, 24 May 2019 10:59:43 -0400
4 Subject: media: smsusb: better handle optional alignment
5
6 From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
7
8 commit a47686636d84eaec5c9c6e84bd5f96bed34d526d upstream.
9
10 Most Siano devices require an alignment for the response.
11
12 Changeset f3be52b0056a ("media: usb: siano: Fix general protection fault in smsusb")
13 changed the logic with gets such aligment, but it now produces a
14 sparce warning:
15
16 drivers/media/usb/siano/smsusb.c: In function 'smsusb_init_device':
17 drivers/media/usb/siano/smsusb.c:447:37: warning: 'in_maxp' may be used uninitialized in this function [-Wmaybe-uninitialized]
18 447 | dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
19 | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
21 The sparse message itself is bogus, but a broken (or fake) USB
22 eeprom could produce a negative value for response_alignment.
23
24 So, change the code in order to check if the result is not
25 negative.
26
27 Fixes: 31e0456de5be ("media: usb: siano: Fix general protection fault in smsusb")
28 CC: <stable@vger.kernel.org>
29 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31
32 ---
33 drivers/media/usb/siano/smsusb.c | 8 ++++----
34 1 file changed, 4 insertions(+), 4 deletions(-)
35
36 --- a/drivers/media/usb/siano/smsusb.c
37 +++ b/drivers/media/usb/siano/smsusb.c
38 @@ -401,7 +401,7 @@ static int smsusb_init_device(struct usb
39 struct smsusb_device_t *dev;
40 void *mdev;
41 int i, rc;
42 - int in_maxp = 0;
43 + int align = 0;
44
45 /* create device object */
46 dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);
47 @@ -419,14 +419,14 @@ static int smsusb_init_device(struct usb
48
49 if (desc->bEndpointAddress & USB_DIR_IN) {
50 dev->in_ep = desc->bEndpointAddress;
51 - in_maxp = usb_endpoint_maxp(desc);
52 + align = usb_endpoint_maxp(desc) - sizeof(struct sms_msg_hdr);
53 } else {
54 dev->out_ep = desc->bEndpointAddress;
55 }
56 }
57
58 pr_debug("in_ep = %02x, out_ep = %02x\n", dev->in_ep, dev->out_ep);
59 - if (!dev->in_ep || !dev->out_ep) { /* Missing endpoints? */
60 + if (!dev->in_ep || !dev->out_ep || align < 0) { /* Missing endpoints? */
61 smsusb_term_device(intf);
62 return -ENODEV;
63 }
64 @@ -445,7 +445,7 @@ static int smsusb_init_device(struct usb
65 /* fall-thru */
66 default:
67 dev->buffer_size = USB2_BUFFER_SIZE;
68 - dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
69 + dev->response_alignment = align;
70
71 params.flags |= SMS_DEVICE_FAMILY2;
72 break;