aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDan Carpenter <error27@gmail.com>2009-12-31 10:42:55 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-03-02 17:53:59 -0500
commitd0ef90b49857b403c1cfa62fce229c967dd4be40 (patch)
tree982354c995a933e5f4e38c48b6ea6d268f9464f1 /drivers
parent96679f6bd5e1ccb30671b81636b4fdc326e46d8a (diff)
USB: serial: fix DMA buffers on stack for io_edgeport.c
The original code was passing a stack variable as a dma buffer, so I made it an allocated variable. Instead of adding a bunch of kfree() calls, I changed all the error return paths to gotos. Also I noticed that the error checking wasn't correct because usb_get_descriptor() can return negative values. While I was at it, I made an unrelated white space change by moving the unicode_to_ascii() on to one line. Signed-off-by: Dan Carpenter <error27@gmail.com> Cc: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/serial/io_edgeport.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index b97960ac92f2..09456002bac0 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -372,31 +372,32 @@ static void update_edgeport_E2PROM(struct edgeport_serial *edge_serial)
372 ************************************************************************/ 372 ************************************************************************/
373static int get_string(struct usb_device *dev, int Id, char *string, int buflen) 373static int get_string(struct usb_device *dev, int Id, char *string, int buflen)
374{ 374{
375 struct usb_string_descriptor StringDesc; 375 struct usb_string_descriptor *StringDesc = NULL;
376 struct usb_string_descriptor *pStringDesc; 376 struct usb_string_descriptor *pStringDesc = NULL;
377 int ret = 0;
377 378
378 dbg("%s - USB String ID = %d", __func__, Id); 379 dbg("%s - USB String ID = %d", __func__, Id);
379 380
380 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, 381 StringDesc = kmalloc(sizeof(*StringDesc), GFP_KERNEL);
381 &StringDesc, sizeof(StringDesc))) 382 if (!StringDesc)
382 return 0; 383 goto free;
384 if (usb_get_descriptor(dev, USB_DT_STRING, Id, StringDesc, sizeof(*StringDesc)) <= 0)
385 goto free;
383 386
384 pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL); 387 pStringDesc = kmalloc(StringDesc->bLength, GFP_KERNEL);
385 if (!pStringDesc) 388 if (!pStringDesc)
386 return 0; 389 goto free;
387 390
388 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, 391 if (usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, StringDesc->bLength) <= 0)
389 pStringDesc, StringDesc.bLength)) { 392 goto free;
390 kfree(pStringDesc);
391 return 0;
392 }
393
394 unicode_to_ascii(string, buflen,
395 pStringDesc->wData, pStringDesc->bLength/2);
396 393
397 kfree(pStringDesc); 394 unicode_to_ascii(string, buflen, pStringDesc->wData, pStringDesc->bLength/2);
395 ret = strlen(string);
398 dbg("%s - USB String %s", __func__, string); 396 dbg("%s - USB String %s", __func__, string);
399 return strlen(string); 397free:
398 kfree(StringDesc);
399 kfree(pStringDesc);
400 return ret;
400} 401}
401 402
402 403