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
6 From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
8 commit a47686636d84eaec5c9c6e84bd5f96bed34d526d upstream.
10 Most Siano devices require an alignment for the response.
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
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 | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 The sparse message itself is bogus, but a broken (or fake) USB
22 eeprom could produce a negative value for response_alignment.
24 So, change the code in order to check if the result is not
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>
33 drivers/media/usb/siano/smsusb.c | 8 ++++----
34 1 file changed, 4 insertions(+), 4 deletions(-)
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;
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
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);
54 dev->out_ep = desc->bEndpointAddress;
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);
64 @@ -445,7 +445,7 @@ static int smsusb_init_device(struct usb
67 dev->buffer_size = USB2_BUFFER_SIZE;
68 - dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
69 + dev->response_alignment = align;
71 params.flags |= SMS_DEVICE_FAMILY2;