stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] media: smsusb: better handle optional alignment
@ 2019-05-24 14:59 Mauro Carvalho Chehab
  2019-05-24 19:09 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2019-05-24 14:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Mauro Carvalho Chehab, Alan Stern, Allison Randal, Steve Winslow,
	Wen Yang, Thomas Gleixner, stable

Most Siano devices require an alignment for the response.

Changeset f3be52b0056a ("media: usb: siano: Fix general protection fault in smsusb")
changed the logic with gets such aligment, but it now produces a
sparce warning:

drivers/media/usb/siano/smsusb.c: In function 'smsusb_init_device':
drivers/media/usb/siano/smsusb.c:447:37: warning: 'in_maxp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  447 |   dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
      |                             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

The sparse message itself is bogus, but a broken (or fake) USB
eeprom could produce a negative value for response_alignment.

So, change the code in order to check if the result is not
negative.

Fixes: f3be52b0056a ("media: usb: siano: Fix general protection fault in smsusb")
CC: <stable@vger.kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
---

Greg,

As the Alan patches went via your tree, please apply this one too.

 drivers/media/usb/siano/smsusb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/siano/smsusb.c b/drivers/media/usb/siano/smsusb.c
index f5e69fdf1242..9ba3a2ae36e5 100644
--- a/drivers/media/usb/siano/smsusb.c
+++ b/drivers/media/usb/siano/smsusb.c
@@ -389,7 +389,7 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
 	struct smsusb_device_t *dev;
 	void *mdev;
 	int i, rc;
-	int in_maxp = 0;
+	int align = 0;
 
 	/* create device object */
 	dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);
@@ -407,14 +407,14 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
 
 		if (desc->bEndpointAddress & USB_DIR_IN) {
 			dev->in_ep = desc->bEndpointAddress;
-			in_maxp = usb_endpoint_maxp(desc);
+			align = usb_endpoint_maxp(desc) - sizeof(struct sms_msg_hdr);
 		} else {
 			dev->out_ep = desc->bEndpointAddress;
 		}
 	}
 
 	pr_debug("in_ep = %02x, out_ep = %02x\n", dev->in_ep, dev->out_ep);
-	if (!dev->in_ep || !dev->out_ep) {	/* Missing endpoints? */
+	if (!dev->in_ep || !dev->out_ep || align < 0) {  /* Missing endpoints? */
 		smsusb_term_device(intf);
 		return -ENODEV;
 	}
@@ -433,7 +433,7 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
 		/* fall-thru */
 	default:
 		dev->buffer_size = USB2_BUFFER_SIZE;
-		dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
+		dev->response_alignment = align;
 
 		params.flags |= SMS_DEVICE_FAMILY2;
 		break;
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] media: smsusb: better handle optional alignment
  2019-05-24 14:59 [PATCH v2] media: smsusb: better handle optional alignment Mauro Carvalho Chehab
@ 2019-05-24 19:09 ` Greg Kroah-Hartman
  2019-05-24 19:22   ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2019-05-24 19:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Alan Stern, Allison Randal, Steve Winslow, Wen Yang,
	Thomas Gleixner, stable

On Fri, May 24, 2019 at 10:59:43AM -0400, Mauro Carvalho Chehab wrote:
> Most Siano devices require an alignment for the response.
> 
> Changeset f3be52b0056a ("media: usb: siano: Fix general protection fault in smsusb")
> changed the logic with gets such aligment, but it now produces a
> sparce warning:
> 
> drivers/media/usb/siano/smsusb.c: In function 'smsusb_init_device':
> drivers/media/usb/siano/smsusb.c:447:37: warning: 'in_maxp' may be used uninitialized in this function [-Wmaybe-uninitialized]
>   447 |   dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
>       |                             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> The sparse message itself is bogus, but a broken (or fake) USB
> eeprom could produce a negative value for response_alignment.
> 
> So, change the code in order to check if the result is not
> negative.
> 
> Fixes: f3be52b0056a ("media: usb: siano: Fix general protection fault in smsusb")
> CC: <stable@vger.kernel.org>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
> ---
> 
> Greg,
> 
> As the Alan patches went via your tree, please apply this one too.

Thanks, now done, and I fixed up the Fixes: sha1 tag to match my tree.

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] media: smsusb: better handle optional alignment
  2019-05-24 19:09 ` Greg Kroah-Hartman
@ 2019-05-24 19:22   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2019-05-24 19:22 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Alan Stern, Allison Randal, Steve Winslow, Wen Yang,
	Thomas Gleixner, stable

Em Fri, 24 May 2019 21:09:41 +0200
Greg Kroah-Hartman <gregkh@linuxfoundation.org> escreveu:

> On Fri, May 24, 2019 at 10:59:43AM -0400, Mauro Carvalho Chehab wrote:
> > Most Siano devices require an alignment for the response.
> > 
> > Changeset f3be52b0056a ("media: usb: siano: Fix general protection fault in smsusb")
> > changed the logic with gets such aligment, but it now produces a
> > sparce warning:
> > 
> > drivers/media/usb/siano/smsusb.c: In function 'smsusb_init_device':
> > drivers/media/usb/siano/smsusb.c:447:37: warning: 'in_maxp' may be used uninitialized in this function [-Wmaybe-uninitialized]
> >   447 |   dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
> >       |                             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > 
> > The sparse message itself is bogus, but a broken (or fake) USB
> > eeprom could produce a negative value for response_alignment.
> > 
> > So, change the code in order to check if the result is not
> > negative.
> > 
> > Fixes: f3be52b0056a ("media: usb: siano: Fix general protection fault in smsusb")
> > CC: <stable@vger.kernel.org>
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
> > ---
> > 
> > Greg,
> > 
> > As the Alan patches went via your tree, please apply this one too.  
> 
> Thanks, now done, and I fixed up the Fixes: sha1 tag to match my tree.

Ah, thanks! I forgot about that :-)

> 
> greg k-h



Thanks,
Mauro

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-24 19:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-24 14:59 [PATCH v2] media: smsusb: better handle optional alignment Mauro Carvalho Chehab
2019-05-24 19:09 ` Greg Kroah-Hartman
2019-05-24 19:22   ` Mauro Carvalho Chehab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).