HID: fix possible deadlock in hidraw_read
authorJiri Kosina <jkosina@suse.cz>
Mon, 12 Oct 2009 09:25:56 +0000 (11:25 +0200)
committerJiri Kosina <jkosina@suse.cz>
Mon, 12 Oct 2009 09:25:56 +0000 (11:25 +0200)
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>
drivers/hid/hidraw.c

index 0c6639ea03dd1748076dd8742035f1f154603cd9..b079a9c59958db7d9116d83e32dd613c187c16a3 100644 (file)
@@ -47,10 +47,9 @@ static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count,
        char *report;
        DECLARE_WAITQUEUE(wait, current);
 
-       while (ret == 0) {
-
-               mutex_lock(&list->read_mutex);
+       mutex_lock(&list->read_mutex);
 
+       while (ret == 0) {
                if (list->head == list->tail) {
                        add_wait_queue(&list->hidraw->wait, &wait);
                        set_current_state(TASK_INTERRUPTIBLE);