Commit 9a79dfce authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: usbdux: tidy up usbdux_ai_cmd()

Rename the local variable used for the private data pointer to the
comedi "norm".

Remove the unnecessary sanity check of the private data pointer. This
function can only be called is the private data was allocated during
the attach.

Tidy up the exit path using goto to ensure that the semaphore is
released.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e5cb2f94
...@@ -882,85 +882,79 @@ static int usbdux_ai_inttrig(struct comedi_device *dev, ...@@ -882,85 +882,79 @@ static int usbdux_ai_inttrig(struct comedi_device *dev,
static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
{ {
struct usbdux_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd; struct comedi_cmd *cmd = &s->async->cmd;
unsigned int chan, range; int len = cmd->chanlist_len;
int i, ret; int ret = -EBUSY;
struct usbdux_private *this_usbduxsub = dev->private; int i;
int result;
if (!this_usbduxsub)
return -EFAULT;
/* block other CPUs from starting an ai_cmd */ /* block other CPUs from starting an ai_cmd */
down(&this_usbduxsub->sem); down(&devpriv->sem);
if (this_usbduxsub->ai_cmd_running) {
up(&this_usbduxsub->sem); if (devpriv->ai_cmd_running)
return -EBUSY; goto ai_cmd_exit;
}
/* set current channel of the running acquisition to zero */ /* set current channel of the running acquisition to zero */
s->async->cur_chan = 0; s->async->cur_chan = 0;
this_usbduxsub->dux_commands[1] = cmd->chanlist_len; devpriv->dux_commands[1] = len;
for (i = 0; i < cmd->chanlist_len; ++i) { for (i = 0; i < len; ++i) {
chan = CR_CHAN(cmd->chanlist[i]); unsigned int chan = CR_CHAN(cmd->chanlist[i]);
range = CR_RANGE(cmd->chanlist[i]); unsigned int range = CR_RANGE(cmd->chanlist[i]);
if (i >= NUMCHANNELS) if (i >= NUMCHANNELS)
break; break;
this_usbduxsub->dux_commands[i + 2] =
create_adc_command(chan, range);
}
result = send_dux_commands(dev, SENDADCOMMANDS); devpriv->dux_commands[i + 2] = create_adc_command(chan, range);
if (result < 0) {
up(&this_usbduxsub->sem);
return result;
} }
if (this_usbduxsub->high_speed) { ret = send_dux_commands(dev, SENDADCOMMANDS);
if (ret < 0)
goto ai_cmd_exit;
if (devpriv->high_speed) {
/* /*
* every channel gets a time window of 125us. Thus, if we * every channel gets a time window of 125us. Thus, if we
* sample all 8 channels we need 1ms. If we sample only one * sample all 8 channels we need 1ms. If we sample only one
* channel we need only 125us * channel we need only 125us
*/ */
this_usbduxsub->ai_interval = 1; devpriv->ai_interval = 1;
/* find a power of 2 for the interval */ /* find a power of 2 for the interval */
while ((this_usbduxsub->ai_interval) < (cmd->chanlist_len)) { while (devpriv->ai_interval < len)
this_usbduxsub->ai_interval = devpriv->ai_interval *= 2;
(this_usbduxsub->ai_interval) * 2;
} devpriv->ai_timer = cmd->scan_begin_arg /
this_usbduxsub->ai_timer = cmd->scan_begin_arg / (125000 * (125000 * devpriv->ai_interval);
(this_usbduxsub->
ai_interval));
} else { } else {
/* interval always 1ms */ /* interval always 1ms */
this_usbduxsub->ai_interval = 1; devpriv->ai_interval = 1;
this_usbduxsub->ai_timer = cmd->scan_begin_arg / 1000000; devpriv->ai_timer = cmd->scan_begin_arg / 1000000;
} }
if (this_usbduxsub->ai_timer < 1) { if (devpriv->ai_timer < 1) {
up(&this_usbduxsub->sem); ret = -EINVAL;
return -EINVAL; goto ai_cmd_exit;
} }
this_usbduxsub->ai_counter = this_usbduxsub->ai_timer;
devpriv->ai_counter = devpriv->ai_timer;
if (cmd->stop_src == TRIG_COUNT) { if (cmd->stop_src == TRIG_COUNT) {
/* data arrives as one packet */ /* data arrives as one packet */
this_usbduxsub->ai_sample_count = cmd->stop_arg; devpriv->ai_sample_count = cmd->stop_arg;
this_usbduxsub->ai_continous = 0; devpriv->ai_continous = 0;
} else { } else {
/* continous acquisition */ /* continous acquisition */
this_usbduxsub->ai_continous = 1; devpriv->ai_continous = 1;
this_usbduxsub->ai_sample_count = 0; devpriv->ai_sample_count = 0;
} }
if (cmd->start_src == TRIG_NOW) { if (cmd->start_src == TRIG_NOW) {
/* enable this acquisition operation */ /* enable this acquisition operation */
this_usbduxsub->ai_cmd_running = 1; devpriv->ai_cmd_running = 1;
ret = usbduxsub_submit_inurbs(dev); ret = usbduxsub_submit_inurbs(dev);
if (ret < 0) { if (ret < 0) {
this_usbduxsub->ai_cmd_running = 0; devpriv->ai_cmd_running = 0;
/* fixme: unlink here?? */ /* fixme: unlink here?? */
up(&this_usbduxsub->sem); goto ai_cmd_exit;
return ret;
} }
s->async->inttrig = NULL; s->async->inttrig = NULL;
} else { } else {
...@@ -969,8 +963,11 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -969,8 +963,11 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
/* wait for an internal signal */ /* wait for an internal signal */
s->async->inttrig = usbdux_ai_inttrig; s->async->inttrig = usbdux_ai_inttrig;
} }
up(&this_usbduxsub->sem);
return 0; ai_cmd_exit:
up(&devpriv->sem);
return ret;
} }
/* Mode 0 is used to get a single conversion on demand */ /* Mode 0 is used to get a single conversion on demand */
......
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