aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2010-11-18 02:59:34 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2010-11-18 03:16:44 -0500
commite3f0f0a6c11b049f1be603dcfec82d2a8643f5fd (patch)
treef77ff559fb6c1af542217627678af719fdc32dce /drivers/input
parent20a4c261ad9cec39942257b1f91765a4b238db05 (diff)
Input: xpad - ensure xpad->bulk_out is initialized before submitting urb
As pointed out by Oliver Neukum: xpad->irq_in is currently submitted before xpad->bulk_out is allocated. That however is a race, because the callback for irq_in can call xpad360w_process_packet(), which will in turn submit the bulk URB. This patch moves initialization for xpad->bulk_out earlier, so we can ensure xpad->bulk_out is initialized before submitting urb. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/joystick/xpad.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 4875de9a3f88..56abf3d0e911 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -921,19 +921,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
921 921
922 usb_set_intfdata(intf, xpad); 922 usb_set_intfdata(intf, xpad);
923 923
924 /*
925 * Submit the int URB immediately rather than waiting for open
926 * because we get status messages from the device whether
927 * or not any controllers are attached. In fact, it's
928 * exactly the message that a controller has arrived that
929 * we're waiting for.
930 */
931 if (xpad->xtype == XTYPE_XBOX360W) { 924 if (xpad->xtype == XTYPE_XBOX360W) {
932 xpad->irq_in->dev = xpad->udev;
933 error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
934 if (error)
935 goto fail7;
936
937 /* 925 /*
938 * Setup the message to set the LEDs on the 926 * Setup the message to set the LEDs on the
939 * controller when it shows up 927 * controller when it shows up
@@ -941,13 +929,13 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
941 xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL); 929 xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL);
942 if (!xpad->bulk_out) { 930 if (!xpad->bulk_out) {
943 error = -ENOMEM; 931 error = -ENOMEM;
944 goto fail8; 932 goto fail7;
945 } 933 }
946 934
947 xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL); 935 xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL);
948 if (!xpad->bdata) { 936 if (!xpad->bdata) {
949 error = -ENOMEM; 937 error = -ENOMEM;
950 goto fail9; 938 goto fail8;
951 } 939 }
952 940
953 xpad->bdata[2] = 0x08; 941 xpad->bdata[2] = 0x08;
@@ -969,12 +957,24 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
969 usb_fill_bulk_urb(xpad->bulk_out, udev, 957 usb_fill_bulk_urb(xpad->bulk_out, udev,
970 usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress), 958 usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress),
971 xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad); 959 xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad);
960
961 /*
962 * Submit the int URB immediately rather than waiting for open
963 * because we get status messages from the device whether
964 * or not any controllers are attached. In fact, it's
965 * exactly the message that a controller has arrived that
966 * we're waiting for.
967 */
968 xpad->irq_in->dev = xpad->udev;
969 error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
970 if (error)
971 goto fail9;
972 } 972 }
973 973
974 return 0; 974 return 0;
975 975
976 fail9: usb_free_urb(xpad->bulk_out); 976 fail9: kfree(xpad->bdata);
977 fail8: usb_kill_urb(xpad->irq_in); 977 fail8: usb_free_urb(xpad->bulk_out);
978 fail7: input_unregister_device(input_dev); 978 fail7: input_unregister_device(input_dev);
979 input_dev = NULL; 979 input_dev = NULL;
980 fail6: xpad_led_disconnect(xpad); 980 fail6: xpad_led_disconnect(xpad);