From: David Herrmann <dh.herrmann@gmail.com>
To: linux-input@vger.kernel.org
Cc: Jiri Kosina <jkosina@suse.cz>,
Benjamin Tissoires <benjamin.tissoires@gmail.com>,
David Herrmann <dh.herrmann@gmail.com>
Subject: [PATCH 06/12] HID: uhid: invert report_done and make non-atomic
Date: Tue, 29 Jul 2014 17:14:20 +0200 [thread overview]
Message-ID: <1406646866-999-7-git-send-email-dh.herrmann@gmail.com> (raw)
In-Reply-To: <1406646866-999-1-git-send-email-dh.herrmann@gmail.com>
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>
---
drivers/hid/uhid.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index db4e119..2d2025a 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);
--
2.0.3
next prev parent reply other threads:[~2014-07-29 15:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 15:14 [PATCH 00/12] HID: Convert UHID to new HID transport-layer David Herrmann
2014-07-29 15:14 ` [PATCH 01/12] HID: uhid: simplify report-cb shutdown David Herrmann
2014-07-29 15:14 ` [PATCH 02/12] HID: uhid: forward create_req to create2_req David Herrmann
2014-07-29 15:14 ` [PATCH 03/12] HID: uhid: avoid dangling pointers in uhid context David Herrmann
2014-07-29 15:14 ` [PATCH 04/12] HID: uhid: avoid magic-numbers when setting strings David Herrmann
2014-07-29 15:14 ` [PATCH 05/12] HID: uhid: turn report_id into u32 David Herrmann
2014-07-29 15:14 ` David Herrmann [this message]
2014-07-29 15:14 ` [PATCH 07/12] HID: uhid: add ABI compatible UHID_GET_REPORT replacing UHID_FEATURE David Herrmann
2014-07-29 15:14 ` [PATCH 08/12] HID: uhid: keep legacy definitions at the bottom of uhid.h David Herrmann
2014-07-29 15:14 ` [PATCH 09/12] HID: uhid: rename uhid_raw_request to uhid_hid_raw_request David Herrmann
2014-07-29 15:14 ` [PATCH 10/12] HID: uhid: implement SET_REPORT David Herrmann
2014-07-29 15:14 ` [PATCH 11/12] HID: uhid: report to user-space whether reports are numbered David Herrmann
2014-07-29 15:14 ` [PATCH 12/12] HID: uhid: update documentation David Herrmann
2014-07-29 19:00 ` [PATCH 00/12] HID: Convert UHID to new HID transport-layer Jiri Kosina
2014-07-29 19:03 ` David Herrmann
2014-08-25 8:34 ` Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1406646866-999-7-git-send-email-dh.herrmann@gmail.com \
--to=dh.herrmann@gmail.com \
--cc=benjamin.tissoires@gmail.com \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).