From: Ian Abbott <abbotti@mev.co.uk>
To: <driverdev-devel@linuxdriverproject.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Ian Abbott <abbotti@mev.co.uk>,
H Hartley Sweeten <hartleys@visionengravers.com>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH 2/7] staging: comedi: comedi_fops: eliminate a use of subdevice spin-lock
Date: Fri, 27 Mar 2015 15:13:01 +0000 [thread overview]
Message-ID: <1427469186-11222-3-git-send-email-abbotti@mev.co.uk> (raw)
In-Reply-To: <1427469186-11222-1-git-send-email-abbotti@mev.co.uk>
`comedi_is_subdevice_in_error()` is only used by `comedi_read()` and
`comedi_write()` and is only called (soon) after
`comedi_is_subdevice_running()` returns `false` (with extra conditions
in the case of `comedi_write()`). `comedi_is_subdevice_running()` and
`comedi_get_subdevice_runflags()` both call
`comedi_get_subdevice_runflags()` which uses the subdevice's spin-lock.
Eliminate one use of the subdevice's spin-lock in `comedi_read()` and
`comedi_write()` by calling `comedi_get_subdevice_runflags()` and
checking the runflags directly. Add a couple of inline functions to
check the runflags: `comedi_is_runflags_running()` and
`comedi_is_runflags_in_error()`. These do the same test on runflags as
`comedi_is_subdevice_running()` and `comedi_is_subdevice_in_error()` but
get passed the runflags value directly.
`comedi_is_subdevice_in_error()` is no longer used, so remove it.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
drivers/staging/comedi/comedi_fops.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 2b75b7a1..17ac285 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -623,6 +623,16 @@ static unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s)
return runflags;
}
+static bool comedi_is_runflags_running(unsigned runflags)
+{
+ return runflags & COMEDI_SRF_RUNNING;
+}
+
+static bool comedi_is_runflags_in_error(unsigned runflags)
+{
+ return runflags & COMEDI_SRF_ERROR;
+}
+
/**
* comedi_is_subdevice_running - check if async command running on subdevice
* @s: comedi_subdevice struct
@@ -634,17 +644,10 @@ bool comedi_is_subdevice_running(struct comedi_subdevice *s)
{
unsigned runflags = comedi_get_subdevice_runflags(s);
- return (runflags & COMEDI_SRF_RUNNING) ? true : false;
+ return comedi_is_runflags_running(runflags);
}
EXPORT_SYMBOL_GPL(comedi_is_subdevice_running);
-static bool comedi_is_subdevice_in_error(struct comedi_subdevice *s)
-{
- unsigned runflags = comedi_get_subdevice_runflags(s);
-
- return (runflags & COMEDI_SRF_ERROR) ? true : false;
-}
-
static bool comedi_is_subdevice_idle(struct comedi_subdevice *s)
{
unsigned runflags = comedi_get_subdevice_runflags(s);
@@ -2282,13 +2285,16 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
add_wait_queue(&async->wait_head, &wait);
on_wait_queue = true;
while (nbytes > 0 && !retval) {
+ unsigned runflags;
+
set_current_state(TASK_INTERRUPTIBLE);
- if (!comedi_is_subdevice_running(s)) {
+ runflags = comedi_get_subdevice_runflags(s);
+ if (!comedi_is_runflags_running(runflags)) {
if (count == 0) {
struct comedi_subdevice *new_s;
- if (comedi_is_subdevice_in_error(s))
+ if (comedi_is_runflags_in_error(runflags))
retval = -EPIPE;
else
retval = 0;
@@ -2435,8 +2441,10 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
n = m;
if (n == 0) {
- if (!comedi_is_subdevice_running(s)) {
- if (comedi_is_subdevice_in_error(s))
+ unsigned runflags = comedi_get_subdevice_runflags(s);
+
+ if (!comedi_is_runflags_running(runflags)) {
+ if (comedi_is_runflags_in_error(runflags))
retval = -EPIPE;
else
retval = 0;
--
2.1.4
next prev parent reply other threads:[~2015-03-27 15:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-27 15:12 [PATCH 0/7] staging: comedi: comedi_fops: some runflag and event handling changes Ian Abbott
2015-03-27 15:13 ` [PATCH 1/7] staging: comedi: comedi_fops: rename comedi_set_subdevice_runflags() Ian Abbott
2015-03-27 15:13 ` Ian Abbott [this message]
2015-03-27 15:13 ` [PATCH 3/7] staging: comedi: comedi_fops: simplify comedi_is_subdevice_idle() Ian Abbott
2015-03-27 15:13 ` [PATCH 4/7] staging: comedi: comedi_fops: remove unnecessary s->async use Ian Abbott
2015-03-27 15:13 ` [PATCH 5/7] staging: comedi: comedi_fops: always clear events Ian Abbott
2015-03-27 15:13 ` [PATCH 6/7] staging: comedi: comedi_fops: send SIGIO according to command direction Ian Abbott
2015-03-27 15:13 ` [PATCH 7/7] staging: comedi: comedi_fops: extend spin-lock scope in comedi_event() Ian Abbott
2015-03-30 16:47 ` Hartley Sweeten
2015-03-31 9:42 ` Ian Abbott
2015-03-31 16:13 ` Hartley Sweeten
2015-04-01 9:10 ` Ian Abbott
2015-03-30 17:13 ` [PATCH 0/7] staging: comedi: comedi_fops: some runflag and event handling changes Hartley Sweeten
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=1427469186-11222-3-git-send-email-abbotti@mev.co.uk \
--to=abbotti@mev.co.uk \
--cc=driverdev-devel@linuxdriverproject.org \
--cc=gregkh@linuxfoundation.org \
--cc=hartleys@visionengravers.com \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®