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>
This commit is contained in:
parent
96679f6bd5
commit
d0ef90b498
|
@ -372,31 +372,32 @@ static void update_edgeport_E2PROM(struct edgeport_serial *edge_serial)
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static int get_string(struct usb_device *dev, int Id, char *string, int buflen)
|
static int get_string(struct usb_device *dev, int Id, char *string, int buflen)
|
||||||
{
|
{
|
||||||
struct usb_string_descriptor StringDesc;
|
struct usb_string_descriptor *StringDesc = NULL;
|
||||||
struct usb_string_descriptor *pStringDesc;
|
struct usb_string_descriptor *pStringDesc = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
dbg("%s - USB String ID = %d", __func__, Id);
|
dbg("%s - USB String ID = %d", __func__, Id);
|
||||||
|
|
||||||
if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
|
StringDesc = kmalloc(sizeof(*StringDesc), GFP_KERNEL);
|
||||||
&StringDesc, sizeof(StringDesc)))
|
if (!StringDesc)
|
||||||
return 0;
|
goto free;
|
||||||
|
if (usb_get_descriptor(dev, USB_DT_STRING, Id, StringDesc, sizeof(*StringDesc)) <= 0)
|
||||||
|
goto free;
|
||||||
|
|
||||||
pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL);
|
pStringDesc = kmalloc(StringDesc->bLength, GFP_KERNEL);
|
||||||
if (!pStringDesc)
|
if (!pStringDesc)
|
||||||
return 0;
|
goto free;
|
||||||
|
|
||||||
if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
|
if (usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, StringDesc->bLength) <= 0)
|
||||||
pStringDesc, StringDesc.bLength)) {
|
goto free;
|
||||||
kfree(pStringDesc);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
unicode_to_ascii(string, buflen,
|
unicode_to_ascii(string, buflen, pStringDesc->wData, pStringDesc->bLength/2);
|
||||||
pStringDesc->wData, pStringDesc->bLength/2);
|
ret = strlen(string);
|
||||||
|
|
||||||
kfree(pStringDesc);
|
|
||||||
dbg("%s - USB String %s", __func__, string);
|
dbg("%s - USB String %s", __func__, string);
|
||||||
return strlen(string);
|
free:
|
||||||
|
kfree(StringDesc);
|
||||||
|
kfree(pStringDesc);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue