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,
return 0;
}
static int ai_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_cmd *cmd)
static int me4000_ai_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_cmd *cmd)
{
const struct me4000_board *thisboard = comedi_board(dev);
int aref;
const struct me4000_board *board = comedi_board(dev);
unsigned int max_diff_chan = board->ai_diff_nchan;
unsigned int aref0 = CR_AREF(cmd->chanlist[0]);
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++) {
if (CR_AREF(cmd->chanlist[i]) != aref) {
dev_err(dev->class_dev,
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
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");
return -EINVAL;
}
}
/* Check whether channels are available for this ending */
if (aref == SDF_DIFF) {
for (i = 0; i < cmd->chanlist_len; i++) {
if (CR_CHAN(cmd->chanlist[i]) >=
thisboard->ai_diff_nchan) {
dev_err(dev->class_dev,
if (aref == SDF_DIFF) {
if (chan >= max_diff_chan) {
dev_dbg(dev->class_dev,
"Channel number to high\n");
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 (aref == SDF_DIFF) {
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,
if (!comedi_range_is_bipolar(s, range)) {
dev_dbg(dev->class_dev,
"Bipolar is not selected in differential mode\n");
return -EINVAL;
}
......@@ -1091,10 +1059,11 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
if (err)
return 4;
/*
* Stage 5. Check the channel list.
*/
if (ai_check_chanlist(dev, s, cmd))
/* Step 5: check channel list if it exists */
if (cmd->chanlist && cmd->chanlist_len > 0)
err |= me4000_ai_check_chanlist(dev, s, cmd);
if (err)
return 5;
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