diff options
author | Jiri Slaby <jirislaby@gmail.com> | 2008-11-23 06:03:20 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2008-11-23 06:03:20 -0500 |
commit | fde5be353e872fe6088d2b1951e56cdfda2042ff (patch) | |
tree | 31e3851f334761ec945fca5d11ba34012b1b59d7 | |
parent | 578f3a35fecabff49bad808c5301313f785b5462 (diff) |
HID: remove setup mutex, fix possible deadlock
It causes recursive locking warning and is unneeded after
introduction of STARTED flag.
* Resume vs. stop is effectively solved by DISCONNECT flag.
* No problem in suspend vs. start -- urb is submitted even after open
which is possible after connect which is called after start.
* Resume vs. start solved by STARTED flag.
* Suspend vs. stop -- no problem in killing urb and timer twice.
Reported-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r-- | drivers/hid/usbhid/hid-core.c | 18 | ||||
-rw-r--r-- | drivers/hid/usbhid/usbhid.h | 1 |
2 files changed, 2 insertions, 17 deletions
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index d746bf8284dd..606369ea24ca 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c | |||
@@ -796,7 +796,6 @@ static int usbhid_start(struct hid_device *hid) | |||
796 | if (insize > HID_MAX_BUFFER_SIZE) | 796 | if (insize > HID_MAX_BUFFER_SIZE) |
797 | insize = HID_MAX_BUFFER_SIZE; | 797 | insize = HID_MAX_BUFFER_SIZE; |
798 | 798 | ||
799 | mutex_lock(&usbhid->setup); | ||
800 | if (hid_alloc_buffers(dev, hid)) { | 799 | if (hid_alloc_buffers(dev, hid)) { |
801 | ret = -ENOMEM; | 800 | ret = -ENOMEM; |
802 | goto fail; | 801 | goto fail; |
@@ -876,7 +875,6 @@ static int usbhid_start(struct hid_device *hid) | |||
876 | hid_dump_device(hid); | 875 | hid_dump_device(hid); |
877 | 876 | ||
878 | set_bit(HID_STARTED, &usbhid->iofl); | 877 | set_bit(HID_STARTED, &usbhid->iofl); |
879 | mutex_unlock(&usbhid->setup); | ||
880 | 878 | ||
881 | return 0; | 879 | return 0; |
882 | 880 | ||
@@ -888,7 +886,6 @@ fail: | |||
888 | usbhid->urbout = NULL; | 886 | usbhid->urbout = NULL; |
889 | usbhid->urbctrl = NULL; | 887 | usbhid->urbctrl = NULL; |
890 | hid_free_buffers(dev, hid); | 888 | hid_free_buffers(dev, hid); |
891 | mutex_unlock(&usbhid->setup); | ||
892 | return ret; | 889 | return ret; |
893 | } | 890 | } |
894 | 891 | ||
@@ -899,7 +896,6 @@ static void usbhid_stop(struct hid_device *hid) | |||
899 | if (WARN_ON(!usbhid)) | 896 | if (WARN_ON(!usbhid)) |
900 | return; | 897 | return; |
901 | 898 | ||
902 | mutex_lock(&usbhid->setup); | ||
903 | clear_bit(HID_STARTED, &usbhid->iofl); | 899 | clear_bit(HID_STARTED, &usbhid->iofl); |
904 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ | 900 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ |
905 | set_bit(HID_DISCONNECTED, &usbhid->iofl); | 901 | set_bit(HID_DISCONNECTED, &usbhid->iofl); |
@@ -928,7 +924,6 @@ static void usbhid_stop(struct hid_device *hid) | |||
928 | usbhid->urbout = NULL; | 924 | usbhid->urbout = NULL; |
929 | 925 | ||
930 | hid_free_buffers(hid_to_usb_dev(hid), hid); | 926 | hid_free_buffers(hid_to_usb_dev(hid), hid); |
931 | mutex_unlock(&usbhid->setup); | ||
932 | } | 927 | } |
933 | 928 | ||
934 | static struct hid_ll_driver usb_hid_driver = { | 929 | static struct hid_ll_driver usb_hid_driver = { |
@@ -1016,7 +1011,6 @@ static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
1016 | 1011 | ||
1017 | hid->driver_data = usbhid; | 1012 | hid->driver_data = usbhid; |
1018 | usbhid->hid = hid; | 1013 | usbhid->hid = hid; |
1019 | mutex_init(&usbhid->setup); /* needed on suspend/resume */ | ||
1020 | 1014 | ||
1021 | ret = hid_add_device(hid); | 1015 | ret = hid_add_device(hid); |
1022 | if (ret) { | 1016 | if (ret) { |
@@ -1051,18 +1045,14 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message) | |||
1051 | struct hid_device *hid = usb_get_intfdata (intf); | 1045 | struct hid_device *hid = usb_get_intfdata (intf); |
1052 | struct usbhid_device *usbhid = hid->driver_data; | 1046 | struct usbhid_device *usbhid = hid->driver_data; |
1053 | 1047 | ||
1054 | mutex_lock(&usbhid->setup); | 1048 | if (!test_bit(HID_STARTED, &usbhid->iofl)) |
1055 | if (!test_bit(HID_STARTED, &usbhid->iofl)) { | ||
1056 | mutex_unlock(&usbhid->setup); | ||
1057 | return 0; | 1049 | return 0; |
1058 | } | ||
1059 | 1050 | ||
1060 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ | 1051 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ |
1061 | set_bit(HID_SUSPENDED, &usbhid->iofl); | 1052 | set_bit(HID_SUSPENDED, &usbhid->iofl); |
1062 | spin_unlock_irq(&usbhid->inlock); | 1053 | spin_unlock_irq(&usbhid->inlock); |
1063 | del_timer_sync(&usbhid->io_retry); | 1054 | del_timer_sync(&usbhid->io_retry); |
1064 | usb_kill_urb(usbhid->urbin); | 1055 | usb_kill_urb(usbhid->urbin); |
1065 | mutex_unlock(&usbhid->setup); | ||
1066 | dev_dbg(&intf->dev, "suspend\n"); | 1056 | dev_dbg(&intf->dev, "suspend\n"); |
1067 | return 0; | 1057 | return 0; |
1068 | } | 1058 | } |
@@ -1073,16 +1063,12 @@ static int hid_resume(struct usb_interface *intf) | |||
1073 | struct usbhid_device *usbhid = hid->driver_data; | 1063 | struct usbhid_device *usbhid = hid->driver_data; |
1074 | int status; | 1064 | int status; |
1075 | 1065 | ||
1076 | mutex_lock(&usbhid->setup); | 1066 | if (!test_bit(HID_STARTED, &usbhid->iofl)) |
1077 | if (!test_bit(HID_STARTED, &usbhid->iofl)) { | ||
1078 | mutex_unlock(&usbhid->setup); | ||
1079 | return 0; | 1067 | return 0; |
1080 | } | ||
1081 | 1068 | ||
1082 | clear_bit(HID_SUSPENDED, &usbhid->iofl); | 1069 | clear_bit(HID_SUSPENDED, &usbhid->iofl); |
1083 | usbhid->retry_delay = 0; | 1070 | usbhid->retry_delay = 0; |
1084 | status = hid_start_in(hid); | 1071 | status = hid_start_in(hid); |
1085 | mutex_unlock(&usbhid->setup); | ||
1086 | dev_dbg(&intf->dev, "resume status %d\n", status); | 1072 | dev_dbg(&intf->dev, "resume status %d\n", status); |
1087 | return status; | 1073 | return status; |
1088 | } | 1074 | } |
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h index 55973ff54008..332abcdf9956 100644 --- a/drivers/hid/usbhid/usbhid.h +++ b/drivers/hid/usbhid/usbhid.h | |||
@@ -74,7 +74,6 @@ struct usbhid_device { | |||
74 | dma_addr_t outbuf_dma; /* Output buffer dma */ | 74 | dma_addr_t outbuf_dma; /* Output buffer dma */ |
75 | spinlock_t outlock; /* Output fifo spinlock */ | 75 | spinlock_t outlock; /* Output fifo spinlock */ |
76 | 76 | ||
77 | struct mutex setup; | ||
78 | unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ | 77 | unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ |
79 | struct timer_list io_retry; /* Retry timer */ | 78 | struct timer_list io_retry; /* Retry timer */ |
80 | unsigned long stop_retry; /* Time to give up, in jiffies */ | 79 | unsigned long stop_retry; /* Time to give up, in jiffies */ |