Commit 161feb2417dd0c4324c2e8da24aaebd30a436d45
Committed by
Dmitry Torokhov
1 parent
6ff92a6db2
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: Axel Lin <axel.lin@gmail.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Showing 1 changed file with 18 additions and 12 deletions Side-by-side Diff
drivers/input/joystick/xpad.c
... | ... | @@ -760,8 +760,9 @@ |
760 | 760 | { |
761 | 761 | struct usb_xpad *xpad = input_get_drvdata(dev); |
762 | 762 | |
763 | - if(xpad->xtype != XTYPE_XBOX360W) | |
763 | + if (xpad->xtype != XTYPE_XBOX360W) | |
764 | 764 | usb_kill_urb(xpad->irq_in); |
765 | + | |
765 | 766 | xpad_stop_output(xpad); |
766 | 767 | } |
767 | 768 | |
768 | 769 | |
769 | 770 | |
... | ... | @@ -896,15 +897,15 @@ |
896 | 897 | |
897 | 898 | error = xpad_init_output(intf, xpad); |
898 | 899 | if (error) |
899 | - goto fail2; | |
900 | + goto fail3; | |
900 | 901 | |
901 | 902 | error = xpad_init_ff(xpad); |
902 | 903 | if (error) |
903 | - goto fail3; | |
904 | + goto fail4; | |
904 | 905 | |
905 | 906 | error = xpad_led_probe(xpad); |
906 | 907 | if (error) |
907 | - goto fail3; | |
908 | + goto fail5; | |
908 | 909 | |
909 | 910 | ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; |
910 | 911 | usb_fill_int_urb(xpad->irq_in, udev, |
... | ... | @@ -916,7 +917,7 @@ |
916 | 917 | |
917 | 918 | error = input_register_device(xpad->dev); |
918 | 919 | if (error) |
919 | - goto fail4; | |
920 | + goto fail6; | |
920 | 921 | |
921 | 922 | usb_set_intfdata(intf, xpad); |
922 | 923 | |
... | ... | @@ -931,7 +932,7 @@ |
931 | 932 | xpad->irq_in->dev = xpad->udev; |
932 | 933 | error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); |
933 | 934 | if (error) |
934 | - goto fail4; | |
935 | + goto fail7; | |
935 | 936 | |
936 | 937 | /* |
937 | 938 | * Setup the message to set the LEDs on the |
938 | 939 | |
... | ... | @@ -940,13 +941,13 @@ |
940 | 941 | xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL); |
941 | 942 | if (!xpad->bulk_out) { |
942 | 943 | error = -ENOMEM; |
943 | - goto fail5; | |
944 | + goto fail8; | |
944 | 945 | } |
945 | 946 | |
946 | 947 | xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL); |
947 | 948 | if (!xpad->bdata) { |
948 | 949 | error = -ENOMEM; |
949 | - goto fail6; | |
950 | + goto fail9; | |
950 | 951 | } |
951 | 952 | |
952 | 953 | xpad->bdata[2] = 0x08; |
... | ... | @@ -972,10 +973,15 @@ |
972 | 973 | |
973 | 974 | return 0; |
974 | 975 | |
975 | - fail6: usb_free_urb(xpad->bulk_out); | |
976 | - fail5: usb_kill_urb(xpad->irq_in); | |
977 | - fail4: usb_free_urb(xpad->irq_in); | |
978 | - fail3: xpad_deinit_output(xpad); | |
976 | + fail9: usb_free_urb(xpad->bulk_out); | |
977 | + fail8: usb_kill_urb(xpad->irq_in); | |
978 | + fail7: input_unregister_device(input_dev); | |
979 | + input_dev = NULL; | |
980 | + fail6: xpad_led_disconnect(xpad); | |
981 | + fail5: if (input_dev) | |
982 | + input_ff_destroy(input_dev); | |
983 | + fail4: xpad_deinit_output(xpad); | |
984 | + fail3: usb_free_urb(xpad->irq_in); | |
979 | 985 | fail2: usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); |
980 | 986 | fail1: input_free_device(input_dev); |
981 | 987 | kfree(xpad); |