Commit abcd7d5d authored by Daniele Bellucci's avatar Daniele Bellucci Committed by Greg Kroah-Hartman

[PATCH] USB: usbvideo cleanup on error

parent 81213932
...@@ -777,7 +777,7 @@ int usbvideo_register( ...@@ -777,7 +777,7 @@ int usbvideo_register(
const struct usb_device_id *id_table) const struct usb_device_id *id_table)
{ {
struct usbvideo *cams; struct usbvideo *cams;
int i, base_size; int i, base_size, result;
/* Check parameters for sanity */ /* Check parameters for sanity */
if ((num_cams <= 0) || (pCams == NULL) || (cbTbl == NULL)) { if ((num_cams <= 0) || (pCams == NULL) || (cbTbl == NULL)) {
...@@ -846,9 +846,13 @@ int usbvideo_register( ...@@ -846,9 +846,13 @@ int usbvideo_register(
up->user_size = num_cams * num_extra; up->user_size = num_cams * num_extra;
up->user_data = (char *) kmalloc(up->user_size, GFP_KERNEL); up->user_data = (char *) kmalloc(up->user_size, GFP_KERNEL);
if (up->user_data == NULL) { if (up->user_data == NULL) {
up->user_size = 0;
err("%s: Failed to allocate user_data (%d. bytes)", err("%s: Failed to allocate user_data (%d. bytes)",
__FUNCTION__, up->user_size); __FUNCTION__, up->user_size);
while (i) {
up = &cams->cam[--i];
kfree(up->user_data);
}
kfree(cams);
return -ENOMEM; return -ENOMEM;
} }
dbg("%s: Allocated cams[%d].user_data=$%p (%d. bytes)", dbg("%s: Allocated cams[%d].user_data=$%p (%d. bytes)",
...@@ -878,9 +882,16 @@ int usbvideo_register( ...@@ -878,9 +882,16 @@ int usbvideo_register(
* If the handle is not yet updated then the probe() will fail. * If the handle is not yet updated then the probe() will fail.
*/ */
*pCams = cams; *pCams = cams;
usb_register(&cams->usbdrv); result = usb_register(&cams->usbdrv);
if (result) {
for (i = 0; i < num_cams; i++) {
struct uvd *up = &cams->cam[i];
kfree(up->user_data);
}
kfree(cams);
}
return 0; return result;
} }
EXPORT_SYMBOL(usbvideo_register); EXPORT_SYMBOL(usbvideo_register);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment