Commit b183a836 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: comedi_fops: eliminate a use of subdevice spin-lock

`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: default avatarIan Abbott <abbotti@mev.co.uk>
Reviewed-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cc64ea42
...@@ -623,6 +623,16 @@ static unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s) ...@@ -623,6 +623,16 @@ static unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s)
return runflags; 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 * comedi_is_subdevice_running - check if async command running on subdevice
* @s: comedi_subdevice struct * @s: comedi_subdevice struct
...@@ -634,17 +644,10 @@ bool comedi_is_subdevice_running(struct comedi_subdevice *s) ...@@ -634,17 +644,10 @@ bool comedi_is_subdevice_running(struct comedi_subdevice *s)
{ {
unsigned runflags = comedi_get_subdevice_runflags(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); 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) static bool comedi_is_subdevice_idle(struct comedi_subdevice *s)
{ {
unsigned runflags = comedi_get_subdevice_runflags(s); unsigned runflags = comedi_get_subdevice_runflags(s);
...@@ -2282,13 +2285,16 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, ...@@ -2282,13 +2285,16 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
add_wait_queue(&async->wait_head, &wait); add_wait_queue(&async->wait_head, &wait);
on_wait_queue = true; on_wait_queue = true;
while (nbytes > 0 && !retval) { while (nbytes > 0 && !retval) {
unsigned runflags;
set_current_state(TASK_INTERRUPTIBLE); 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) { if (count == 0) {
struct comedi_subdevice *new_s; struct comedi_subdevice *new_s;
if (comedi_is_subdevice_in_error(s)) if (comedi_is_runflags_in_error(runflags))
retval = -EPIPE; retval = -EPIPE;
else else
retval = 0; retval = 0;
...@@ -2435,8 +2441,10 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, ...@@ -2435,8 +2441,10 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
n = m; n = m;
if (n == 0) { if (n == 0) {
if (!comedi_is_subdevice_running(s)) { unsigned runflags = comedi_get_subdevice_runflags(s);
if (comedi_is_subdevice_in_error(s))
if (!comedi_is_runflags_running(runflags)) {
if (comedi_is_runflags_in_error(runflags))
retval = -EPIPE; retval = -EPIPE;
else else
retval = 0; retval = 0;
......
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