diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2014-07-29 17:14:20 +0200 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2014-08-25 03:28:07 -0500 |
commit | 5942b849b124c54002346e699f50db3714e300ed (patch) | |
tree | f49c56e28025b2b8b8650f60a414069e85e5fa18 /drivers/hid | |
parent | 8cad5b017178bd7fa56d5039478d46964bcd94f7 (diff) | |
download | linux-5942b849b124c54002346e699f50db3714e300ed.tar.bz2 |
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: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/uhid.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c index db4e119cb088..2d2025a027fe 100644 --- a/drivers/hid/uhid.c +++ b/drivers/hid/uhid.c @@ -47,7 +47,7 @@ struct uhid_device { /* blocking GET_REPORT support; state changes protected by qlock */ struct mutex report_lock; wait_queue_head_t report_wait; - atomic_t report_done; + bool report_running; u32 report_id; struct uhid_event report_buf; }; @@ -168,13 +168,13 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum, ev->u.feature.rnum = rnum; ev->u.feature.rtype = report_type; - atomic_set(&uhid->report_done, 0); + uhid->report_running = true; uhid_queue(uhid, ev); spin_unlock_irqrestore(&uhid->qlock, flags); ret = wait_event_interruptible_timeout(uhid->report_wait, - atomic_read(&uhid->report_done) || !uhid->running, - 5 * HZ); + !uhid->report_running || !uhid->running, + 5 * HZ); if (!ret || !uhid->running) { ret = -EIO; @@ -196,7 +196,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum, spin_unlock_irqrestore(&uhid->qlock, flags); } - atomic_set(&uhid->report_done, 1); + uhid->report_running = false; unlock: mutex_unlock(&uhid->report_lock); @@ -500,11 +500,11 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid, /* id for old report; drop it silently */ if (uhid->report_id != ev->u.feature_answer.id) goto unlock; - if (atomic_read(&uhid->report_done)) + if (!uhid->report_running) goto unlock; memcpy(&uhid->report_buf, ev, sizeof(*ev)); - atomic_set(&uhid->report_done, 1); + uhid->report_running = false; wake_up_interruptible(&uhid->report_wait); unlock: @@ -526,7 +526,6 @@ static int uhid_char_open(struct inode *inode, struct file *file) init_waitqueue_head(&uhid->waitq); init_waitqueue_head(&uhid->report_wait); uhid->running = false; - atomic_set(&uhid->report_done, 1); file->private_data = uhid; nonseekable_open(inode, file); |