Commit ab366c1a authored by Kulikov Vasiliy's avatar Kulikov Vasiliy Committed by Greg Kroah-Hartman

Staging: line6: fix leaks in line6_probe()

If error occurs line6_probe() must put interface and usbdev that were
got before.
Signed-off-by: default avatarKulikov Vasiliy <segooon@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 8e2394a9
...@@ -679,8 +679,10 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_ ...@@ -679,8 +679,10 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_
usb_get_dev(usbdev); usb_get_dev(usbdev);
/* we don't handle multiple configurations */ /* we don't handle multiple configurations */
if (usbdev->descriptor.bNumConfigurations != 1) if (usbdev->descriptor.bNumConfigurations != 1) {
return -ENODEV; ret = -ENODEV;
goto err_put;
}
/* check vendor and product id */ /* check vendor and product id */
for (devtype = ARRAY_SIZE(line6_id_table) - 1; devtype--;) { for (devtype = ARRAY_SIZE(line6_id_table) - 1; devtype--;) {
...@@ -692,16 +694,20 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_ ...@@ -692,16 +694,20 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_
break; break;
} }
if (devtype < 0) if (devtype < 0) {
return -ENODEV; ret = -ENODEV;
goto err_put;
}
/* find free slot in device table: */ /* find free slot in device table: */
for (devnum = 0; devnum < LINE6_MAX_DEVICES; ++devnum) for (devnum = 0; devnum < LINE6_MAX_DEVICES; ++devnum)
if (line6_devices[devnum] == NULL) if (line6_devices[devnum] == NULL)
break; break;
if (devnum == LINE6_MAX_DEVICES) if (devnum == LINE6_MAX_DEVICES) {
return -ENODEV; ret = -ENODEV;
goto err_put;
}
/* initialize device info: */ /* initialize device info: */
properties = &line6_properties_table[devtype]; properties = &line6_properties_table[devtype];
...@@ -762,13 +768,14 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_ ...@@ -762,13 +768,14 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_
default: default:
MISSING_CASE; MISSING_CASE;
return -ENODEV; ret = -ENODEV;
goto err_put;
} }
ret = usb_set_interface(usbdev, interface_number, alternate); ret = usb_set_interface(usbdev, interface_number, alternate);
if (ret < 0) { if (ret < 0) {
dev_err(&interface->dev, "set_interface failed\n"); dev_err(&interface->dev, "set_interface failed\n");
return ret; goto err_put;
} }
/* initialize device data based on product id: */ /* initialize device data based on product id: */
...@@ -815,7 +822,8 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_ ...@@ -815,7 +822,8 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_
break; break;
default: default:
return -ENODEV; ret = -ENODEV;
goto err_put;
} }
break; break;
...@@ -827,19 +835,22 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_ ...@@ -827,19 +835,22 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_
default: default:
MISSING_CASE; MISSING_CASE;
return -ENODEV; ret = -ENODEV;
goto err_put;
} }
if (size == 0) { if (size == 0) {
dev_err(line6->ifcdev, "driver bug: interface data size not set\n"); dev_err(line6->ifcdev, "driver bug: interface data size not set\n");
return -ENODEV; ret = -ENODEV;
goto err_put;
} }
line6 = kzalloc(size, GFP_KERNEL); line6 = kzalloc(size, GFP_KERNEL);
if (line6 == NULL) { if (line6 == NULL) {
dev_err(&interface->dev, "Out of memory\n"); dev_err(&interface->dev, "Out of memory\n");
return -ENOMEM; ret = -ENODEV;
goto err_put;
} }
/* store basic data: */ /* store basic data: */
...@@ -875,16 +886,16 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_ ...@@ -875,16 +886,16 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_
if (line6->buffer_listen == NULL) { if (line6->buffer_listen == NULL) {
dev_err(&interface->dev, "Out of memory\n"); dev_err(&interface->dev, "Out of memory\n");
line6_destruct(interface); ret = -ENOMEM;
return -ENOMEM; goto err_destruct;
} }
line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL); line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
if (line6->buffer_message == NULL) { if (line6->buffer_message == NULL) {
dev_err(&interface->dev, "Out of memory\n"); dev_err(&interface->dev, "Out of memory\n");
line6_destruct(interface); ret = -ENOMEM;
return -ENOMEM; goto err_destruct;
} }
line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL); line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
...@@ -892,15 +903,15 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_ ...@@ -892,15 +903,15 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_
if (line6->urb_listen == NULL) { if (line6->urb_listen == NULL) {
dev_err(&interface->dev, "Out of memory\n"); dev_err(&interface->dev, "Out of memory\n");
line6_destruct(interface); line6_destruct(interface);
return -ENOMEM; ret = -ENOMEM;
goto err_destruct;
} }
ret = line6_start_listen(line6); ret = line6_start_listen(line6);
if (ret < 0) { if (ret < 0) {
dev_err(&interface->dev, "%s: usb_submit_urb failed\n", dev_err(&interface->dev, "%s: usb_submit_urb failed\n",
__func__); __func__);
line6_destruct(interface); goto err_destruct;
return ret;
} }
} }
...@@ -952,22 +963,25 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_ ...@@ -952,22 +963,25 @@ static int line6_probe(struct usb_interface *interface, const struct usb_device_
ret = -ENODEV; ret = -ENODEV;
} }
if (ret < 0) { if (ret < 0)
line6_destruct(interface); goto err_destruct;
return ret;
}
ret = sysfs_create_link(&interface->dev.kobj, &usbdev->dev.kobj, ret = sysfs_create_link(&interface->dev.kobj, &usbdev->dev.kobj,
"usb_device"); "usb_device");
if (ret < 0) { if (ret < 0)
line6_destruct(interface); goto err_destruct;
return ret;
}
dev_info(&interface->dev, "Line6 %s now attached\n", dev_info(&interface->dev, "Line6 %s now attached\n",
line6->properties->name); line6->properties->name);
line6_devices[devnum] = line6; line6_devices[devnum] = line6;
line6_list_devices(); line6_list_devices();
return 0;
err_destruct:
line6_destruct(interface);
err_put:
usb_put_intf(interface);
usb_put_dev(usbdev);
return ret; return ret;
} }
......
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