HID: fix possible deadlock in hidraw_read
If the loop in hidraw_read() loops more than once, then we might
end up trying to acquire already locked mutex, casuing a deadlock.
Reported-by: iceberg <iceberg@ispras.ru>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 0c6639e..b079a9c 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -47,10 +47,9 @@
char *report;
DECLARE_WAITQUEUE(wait, current);
+ mutex_lock(&list->read_mutex);
+
while (ret == 0) {
-
- mutex_lock(&list->read_mutex);
-
if (list->head == list->tail) {
add_wait_queue(&list->hidraw->wait, &wait);
set_current_state(TASK_INTERRUPTIBLE);