Commit 926e5073 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: me4000: tidy up the chanlist checking

The ai_check_chanlist() function validates that the cmd->chanlist is compatible
with the hardware. This is step 5 of the (*do_cmdtest).

For aesthetics, rename this function so it has namespace associated with the
driver and tidy up the code.

To minimize the noise, change the dev_err() to dev_dbg().
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 368c2dcd
...@@ -598,67 +598,35 @@ static int me4000_ai_cancel(struct comedi_device *dev, ...@@ -598,67 +598,35 @@ static int me4000_ai_cancel(struct comedi_device *dev,
return 0; return 0;
} }
static int ai_check_chanlist(struct comedi_device *dev, static int me4000_ai_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_cmd *cmd) struct comedi_subdevice *s,
struct comedi_cmd *cmd)
{ {
const struct me4000_board *thisboard = comedi_board(dev); const struct me4000_board *board = comedi_board(dev);
int aref; unsigned int max_diff_chan = board->ai_diff_nchan;
unsigned int aref0 = CR_AREF(cmd->chanlist[0]);
int i; int i;
/* Check whether a channel list is available */
if (!cmd->chanlist_len) {
dev_err(dev->class_dev, "No channel list available\n");
return -EINVAL;
}
/* Check the channel list size */
if (cmd->chanlist_len > ME4000_AI_CHANNEL_LIST_COUNT) {
dev_err(dev->class_dev, "Channel list is to large\n");
return -EINVAL;
}
/* Check the pointer */
if (!cmd->chanlist) {
dev_err(dev->class_dev, "NULL pointer to channel list\n");
return -EFAULT;
}
/* Check whether aref is equal for all entries */
aref = CR_AREF(cmd->chanlist[0]);
for (i = 0; i < cmd->chanlist_len; i++) { for (i = 0; i < cmd->chanlist_len; i++) {
if (CR_AREF(cmd->chanlist[i]) != aref) { unsigned int chan = CR_CHAN(cmd->chanlist[i]);
dev_err(dev->class_dev, unsigned int range = CR_RANGE(cmd->chanlist[i]);
unsigned int aref = CR_AREF(cmd->chanlist[i]);
if (aref != aref0) {
dev_dbg(dev->class_dev,
"Mode is not equal for all entries\n"); "Mode is not equal for all entries\n");
return -EINVAL; return -EINVAL;
} }
}
/* Check whether channels are available for this ending */ if (aref == SDF_DIFF) {
if (aref == SDF_DIFF) { if (chan >= max_diff_chan) {
for (i = 0; i < cmd->chanlist_len; i++) { dev_dbg(dev->class_dev,
if (CR_CHAN(cmd->chanlist[i]) >=
thisboard->ai_diff_nchan) {
dev_err(dev->class_dev,
"Channel number to high\n"); "Channel number to high\n");
return -EINVAL; return -EINVAL;
} }
}
} else {
for (i = 0; i < cmd->chanlist_len; i++) {
if (CR_CHAN(cmd->chanlist[i]) >= thisboard->ai_nchan) {
dev_err(dev->class_dev,
"Channel number to high\n");
return -EINVAL;
}
}
}
/* Check if bipolar is set for all entries when in differential mode */ if (!comedi_range_is_bipolar(s, range)) {
if (aref == SDF_DIFF) { dev_dbg(dev->class_dev,
for (i = 0; i < cmd->chanlist_len; i++) {
if (CR_RANGE(cmd->chanlist[i]) != 1 &&
CR_RANGE(cmd->chanlist[i]) != 2) {
dev_err(dev->class_dev,
"Bipolar is not selected in differential mode\n"); "Bipolar is not selected in differential mode\n");
return -EINVAL; return -EINVAL;
} }
...@@ -1091,10 +1059,11 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev, ...@@ -1091,10 +1059,11 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
if (err) if (err)
return 4; return 4;
/* /* Step 5: check channel list if it exists */
* Stage 5. Check the channel list. if (cmd->chanlist && cmd->chanlist_len > 0)
*/ err |= me4000_ai_check_chanlist(dev, s, cmd);
if (ai_check_chanlist(dev, s, cmd))
if (err)
return 5; return 5;
return 0; return 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