diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2014-07-29 11:14:20 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2014-08-25 04:28:07 -0400 |
commit | 5942b849b124c54002346e699f50db3714e300ed (patch) | |
tree | f49c56e28025b2b8b8650f60a414069e85e5fa18 | |
parent | 8cad5b017178bd7fa56d5039478d46964bcd94f7 (diff) |
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>
-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 { | |||
47 | /* blocking GET_REPORT support; state changes protected by qlock */ | 47 | /* blocking GET_REPORT support; state changes protected by qlock */ |
48 | struct mutex report_lock; | 48 | struct mutex report_lock; |
49 | wait_queue_head_t report_wait; | 49 | wait_queue_head_t report_wait; |
50 | atomic_t report_done; | 50 | bool report_running; |
51 | u32 report_id; | 51 | u32 report_id; |
52 | struct uhid_event report_buf; | 52 | struct uhid_event report_buf; |
53 | }; | 53 | }; |
@@ -168,13 +168,13 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum, | |||
168 | ev->u.feature.rnum = rnum; | 168 | ev->u.feature.rnum = rnum; |
169 | ev->u.feature.rtype = report_type; | 169 | ev->u.feature.rtype = report_type; |
170 | 170 | ||
171 | atomic_set(&uhid->report_done, 0); | 171 | uhid->report_running = true; |
172 | uhid_queue(uhid, ev); | 172 | uhid_queue(uhid, ev); |
173 | spin_unlock_irqrestore(&uhid->qlock, flags); | 173 | spin_unlock_irqrestore(&uhid->qlock, flags); |
174 | 174 | ||
175 | ret = wait_event_interruptible_timeout(uhid->report_wait, | 175 | ret = wait_event_interruptible_timeout(uhid->report_wait, |
176 | atomic_read(&uhid->report_done) || !uhid->running, | 176 | !uhid->report_running || !uhid->running, |
177 | 5 * HZ); | 177 | 5 * HZ); |
178 | 178 | ||
179 | if (!ret || !uhid->running) { | 179 | if (!ret || !uhid->running) { |
180 | ret = -EIO; | 180 | ret = -EIO; |
@@ -196,7 +196,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum, | |||
196 | spin_unlock_irqrestore(&uhid->qlock, flags); | 196 | spin_unlock_irqrestore(&uhid->qlock, flags); |
197 | } | 197 | } |
198 | 198 | ||
199 | atomic_set(&uhid->report_done, 1); | 199 | uhid->report_running = false; |
200 | 200 | ||
201 | unlock: | 201 | unlock: |
202 | mutex_unlock(&uhid->report_lock); | 202 | mutex_unlock(&uhid->report_lock); |
@@ -500,11 +500,11 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid, | |||
500 | /* id for old report; drop it silently */ | 500 | /* id for old report; drop it silently */ |
501 | if (uhid->report_id != ev->u.feature_answer.id) | 501 | if (uhid->report_id != ev->u.feature_answer.id) |
502 | goto unlock; | 502 | goto unlock; |
503 | if (atomic_read(&uhid->report_done)) | 503 | if (!uhid->report_running) |
504 | goto unlock; | 504 | goto unlock; |
505 | 505 | ||
506 | memcpy(&uhid->report_buf, ev, sizeof(*ev)); | 506 | memcpy(&uhid->report_buf, ev, sizeof(*ev)); |
507 | atomic_set(&uhid->report_done, 1); | 507 | uhid->report_running = false; |
508 | wake_up_interruptible(&uhid->report_wait); | 508 | wake_up_interruptible(&uhid->report_wait); |
509 | 509 | ||
510 | unlock: | 510 | unlock: |
@@ -526,7 +526,6 @@ static int uhid_char_open(struct inode *inode, struct file *file) | |||
526 | init_waitqueue_head(&uhid->waitq); | 526 | init_waitqueue_head(&uhid->waitq); |
527 | init_waitqueue_head(&uhid->report_wait); | 527 | init_waitqueue_head(&uhid->report_wait); |
528 | uhid->running = false; | 528 | uhid->running = false; |
529 | atomic_set(&uhid->report_done, 1); | ||
530 | 529 | ||
531 | file->private_data = uhid; | 530 | file->private_data = uhid; |
532 | nonseekable_open(inode, file); | 531 | nonseekable_open(inode, file); |