Commit 161feb24 authored by Axel Lin's avatar Axel Lin Committed by Dmitry Torokhov

Input: xpad - fix resource reclaim in xpad_probe error path

Properly free the resources in error path by the reverse order of resource
allocation.
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 6ff92a6d
...@@ -760,8 +760,9 @@ static void xpad_close(struct input_dev *dev) ...@@ -760,8 +760,9 @@ static void xpad_close(struct input_dev *dev)
{ {
struct usb_xpad *xpad = input_get_drvdata(dev); struct usb_xpad *xpad = input_get_drvdata(dev);
if(xpad->xtype != XTYPE_XBOX360W) if (xpad->xtype != XTYPE_XBOX360W)
usb_kill_urb(xpad->irq_in); usb_kill_urb(xpad->irq_in);
xpad_stop_output(xpad); xpad_stop_output(xpad);
} }
...@@ -896,15 +897,15 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id ...@@ -896,15 +897,15 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
error = xpad_init_output(intf, xpad); error = xpad_init_output(intf, xpad);
if (error) if (error)
goto fail2; goto fail3;
error = xpad_init_ff(xpad); error = xpad_init_ff(xpad);
if (error) if (error)
goto fail3; goto fail4;
error = xpad_led_probe(xpad); error = xpad_led_probe(xpad);
if (error) if (error)
goto fail3; goto fail5;
ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
usb_fill_int_urb(xpad->irq_in, udev, usb_fill_int_urb(xpad->irq_in, udev,
...@@ -916,7 +917,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id ...@@ -916,7 +917,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
error = input_register_device(xpad->dev); error = input_register_device(xpad->dev);
if (error) if (error)
goto fail4; goto fail6;
usb_set_intfdata(intf, xpad); usb_set_intfdata(intf, xpad);
...@@ -931,7 +932,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id ...@@ -931,7 +932,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
xpad->irq_in->dev = xpad->udev; xpad->irq_in->dev = xpad->udev;
error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
if (error) if (error)
goto fail4; goto fail7;
/* /*
* Setup the message to set the LEDs on the * Setup the message to set the LEDs on the
...@@ -940,13 +941,13 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id ...@@ -940,13 +941,13 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL); xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL);
if (!xpad->bulk_out) { if (!xpad->bulk_out) {
error = -ENOMEM; error = -ENOMEM;
goto fail5; goto fail8;
} }
xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL); xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL);
if (!xpad->bdata) { if (!xpad->bdata) {
error = -ENOMEM; error = -ENOMEM;
goto fail6; goto fail9;
} }
xpad->bdata[2] = 0x08; xpad->bdata[2] = 0x08;
...@@ -972,10 +973,15 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id ...@@ -972,10 +973,15 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
return 0; return 0;
fail6: usb_free_urb(xpad->bulk_out); fail9: usb_free_urb(xpad->bulk_out);
fail5: usb_kill_urb(xpad->irq_in); fail8: usb_kill_urb(xpad->irq_in);
fail4: usb_free_urb(xpad->irq_in); fail7: input_unregister_device(input_dev);
fail3: xpad_deinit_output(xpad); input_dev = NULL;
fail6: xpad_led_disconnect(xpad);
fail5: if (input_dev)
input_ff_destroy(input_dev);
fail4: xpad_deinit_output(xpad);
fail3: usb_free_urb(xpad->irq_in);
fail2: usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); fail2: usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
fail1: input_free_device(input_dev); fail1: input_free_device(input_dev);
kfree(xpad); kfree(xpad);
......
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