Commit 5942b849 authored by David Herrmann's avatar David Herrmann Committed by Jiri Kosina

HID: uhid: invert report_done and make non-atomic

All accesses to @report_done are protected by qlock (or report-contexts).
No need to use an atomic.

While at it, invert the logic and call it "report_running". This is
similar to the uhid->running field and easier to read.
Signed-off-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 8cad5b01
...@@ -47,7 +47,7 @@ struct uhid_device { ...@@ -47,7 +47,7 @@ struct uhid_device {
/* blocking GET_REPORT support; state changes protected by qlock */ /* blocking GET_REPORT support; state changes protected by qlock */
struct mutex report_lock; struct mutex report_lock;
wait_queue_head_t report_wait; wait_queue_head_t report_wait;
atomic_t report_done; bool report_running;
u32 report_id; u32 report_id;
struct uhid_event report_buf; struct uhid_event report_buf;
}; };
...@@ -168,12 +168,12 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum, ...@@ -168,12 +168,12 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
ev->u.feature.rnum = rnum; ev->u.feature.rnum = rnum;
ev->u.feature.rtype = report_type; ev->u.feature.rtype = report_type;
atomic_set(&uhid->report_done, 0); uhid->report_running = true;
uhid_queue(uhid, ev); uhid_queue(uhid, ev);
spin_unlock_irqrestore(&uhid->qlock, flags); spin_unlock_irqrestore(&uhid->qlock, flags);
ret = wait_event_interruptible_timeout(uhid->report_wait, ret = wait_event_interruptible_timeout(uhid->report_wait,
atomic_read(&uhid->report_done) || !uhid->running, !uhid->report_running || !uhid->running,
5 * HZ); 5 * HZ);
if (!ret || !uhid->running) { if (!ret || !uhid->running) {
...@@ -196,7 +196,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum, ...@@ -196,7 +196,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
spin_unlock_irqrestore(&uhid->qlock, flags); spin_unlock_irqrestore(&uhid->qlock, flags);
} }
atomic_set(&uhid->report_done, 1); uhid->report_running = false;
unlock: unlock:
mutex_unlock(&uhid->report_lock); mutex_unlock(&uhid->report_lock);
...@@ -500,11 +500,11 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid, ...@@ -500,11 +500,11 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
/* id for old report; drop it silently */ /* id for old report; drop it silently */
if (uhid->report_id != ev->u.feature_answer.id) if (uhid->report_id != ev->u.feature_answer.id)
goto unlock; goto unlock;
if (atomic_read(&uhid->report_done)) if (!uhid->report_running)
goto unlock; goto unlock;
memcpy(&uhid->report_buf, ev, sizeof(*ev)); memcpy(&uhid->report_buf, ev, sizeof(*ev));
atomic_set(&uhid->report_done, 1); uhid->report_running = false;
wake_up_interruptible(&uhid->report_wait); wake_up_interruptible(&uhid->report_wait);
unlock: unlock:
...@@ -526,7 +526,6 @@ static int uhid_char_open(struct inode *inode, struct file *file) ...@@ -526,7 +526,6 @@ static int uhid_char_open(struct inode *inode, struct file *file)
init_waitqueue_head(&uhid->waitq); init_waitqueue_head(&uhid->waitq);
init_waitqueue_head(&uhid->report_wait); init_waitqueue_head(&uhid->report_wait);
uhid->running = false; uhid->running = false;
atomic_set(&uhid->report_done, 1);
file->private_data = uhid; file->private_data = uhid;
nonseekable_open(inode, file); nonseekable_open(inode, file);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment