Merge branch 'master' of /pub/scm/linux/kernel/git/jejb/scsi-post-merge-2.6 into...
[firefly-linux-kernel-4.4.55.git] / drivers / input / joystick / xpad.c
index 39c0265ca156d7c5633cdee9b1375a01ff1ea0b5..56abf3d0e911236d4d2972860ba1521072a4a4d2 100644 (file)
@@ -732,7 +732,7 @@ static void xpad_led_disconnect(struct usb_xpad *xpad)
 
        if (xpad_led) {
                led_classdev_unregister(&xpad_led->led_cdev);
-               kfree(xpad_led->name);
+               kfree(xpad_led);
        }
 }
 #else
@@ -760,8 +760,9 @@ static void xpad_close(struct input_dev *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);
+
        xpad_stop_output(xpad);
 }
 
@@ -896,15 +897,15 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
 
        error = xpad_init_output(intf, xpad);
        if (error)
-               goto fail2;
+               goto fail3;
 
        error = xpad_init_ff(xpad);
        if (error)
-               goto fail3;
+               goto fail4;
 
        error = xpad_led_probe(xpad);
        if (error)
-               goto fail3;
+               goto fail5;
 
        ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
        usb_fill_int_urb(xpad->irq_in, udev,
@@ -916,23 +917,11 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
 
        error = input_register_device(xpad->dev);
        if (error)
-               goto fail4;
+               goto fail6;
 
        usb_set_intfdata(intf, xpad);
 
-       /*
-        * Submit the int URB immediatly rather than waiting for open
-        * because we get status messages from the device whether
-        * or not any controllers are attached.  In fact, it's
-        * exactly the message that a controller has arrived that
-        * we're waiting for.
-        */
        if (xpad->xtype == XTYPE_XBOX360W) {
-               xpad->irq_in->dev = xpad->udev;
-               error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
-               if (error)
-                       goto fail4;
-
                /*
                 * Setup the message to set the LEDs on the
                 * controller when it shows up
@@ -940,13 +929,13 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
                xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL);
                if (!xpad->bulk_out) {
                        error = -ENOMEM;
-                       goto fail5;
+                       goto fail7;
                }
 
                xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL);
                if (!xpad->bdata) {
                        error = -ENOMEM;
-                       goto fail6;
+                       goto fail8;
                }
 
                xpad->bdata[2] = 0x08;
@@ -968,14 +957,31 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
                usb_fill_bulk_urb(xpad->bulk_out, udev,
                                usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress),
                                xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad);
+
+               /*
+                * Submit the int URB immediately rather than waiting for open
+                * because we get status messages from the device whether
+                * or not any controllers are attached.  In fact, it's
+                * exactly the message that a controller has arrived that
+                * we're waiting for.
+                */
+               xpad->irq_in->dev = xpad->udev;
+               error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
+               if (error)
+                       goto fail9;
        }
 
        return 0;
 
- fail6:        usb_free_urb(xpad->bulk_out);
- fail5:        usb_kill_urb(xpad->irq_in);
- fail4:        usb_free_urb(xpad->irq_in);
- fail3:        xpad_deinit_output(xpad);
+ fail9:        kfree(xpad->bdata);
+ fail8:        usb_free_urb(xpad->bulk_out);
+ fail7:        input_unregister_device(input_dev);
+       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);
  fail1:        input_free_device(input_dev);
        kfree(xpad);
@@ -987,21 +993,24 @@ static void xpad_disconnect(struct usb_interface *intf)
 {
        struct usb_xpad *xpad = usb_get_intfdata (intf);
 
-       usb_set_intfdata(intf, NULL);
-       if (xpad) {
-               xpad_led_disconnect(xpad);
-               input_unregister_device(xpad->dev);
-               xpad_deinit_output(xpad);
-               if (xpad->xtype == XTYPE_XBOX360W) {
-                       usb_kill_urb(xpad->bulk_out);
-                       usb_free_urb(xpad->bulk_out);
-                       usb_kill_urb(xpad->irq_in);
-               }
-               usb_free_urb(xpad->irq_in);
-               usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
-                               xpad->idata, xpad->idata_dma);
-               kfree(xpad);
+       xpad_led_disconnect(xpad);
+       input_unregister_device(xpad->dev);
+       xpad_deinit_output(xpad);
+
+       if (xpad->xtype == XTYPE_XBOX360W) {
+               usb_kill_urb(xpad->bulk_out);
+               usb_free_urb(xpad->bulk_out);
+               usb_kill_urb(xpad->irq_in);
        }
+
+       usb_free_urb(xpad->irq_in);
+       usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
+                       xpad->idata, xpad->idata_dma);
+
+       kfree(xpad->bdata);
+       kfree(xpad);
+
+       usb_set_intfdata(intf, NULL);
 }
 
 static struct usb_driver xpad_driver = {
@@ -1013,10 +1022,7 @@ static struct usb_driver xpad_driver = {
 
 static int __init usb_xpad_init(void)
 {
-       int result = usb_register(&xpad_driver);
-       if (result == 0)
-               printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
-       return result;
+       return usb_register(&xpad_driver);
 }
 
 static void __exit usb_xpad_exit(void)