Commit 065b0912 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: range: tidy up comedi_check_chanlist()

The only difference in the if() and else if() check of the chanlist
is the source of the range table length. Consolidate the checks to
make the function a bit more concise.
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 eee7d9e9
...@@ -127,38 +127,35 @@ static int aref_invalid(struct comedi_subdevice *s, unsigned int chanspec) ...@@ -127,38 +127,35 @@ static int aref_invalid(struct comedi_subdevice *s, unsigned int chanspec)
return 1; return 1;
} }
/* /**
This function checks each element in a channel/gain list to make * comedi_check_chanlist() - Validate each element in a chanlist.
make sure it is valid. * @s: comedi_subdevice struct
* @n: number of elements in the chanlist
* @chanlist: the chanlist to validate
*/ */
int comedi_check_chanlist(struct comedi_subdevice *s, int n, int comedi_check_chanlist(struct comedi_subdevice *s, int n,
unsigned int *chanlist) unsigned int *chanlist)
{ {
struct comedi_device *dev = s->device; struct comedi_device *dev = s->device;
int i; unsigned int chanspec;
int chan; int chan, range_len, i;
if (s->range_table) { if (s->range_table || s->range_table_list) {
for (i = 0; i < n; i++)
if (CR_CHAN(chanlist[i]) >= s->n_chan ||
CR_RANGE(chanlist[i]) >= s->range_table->length
|| aref_invalid(s, chanlist[i])) {
dev_warn(dev->class_dev,
"bad chanlist[%d]=0x%08x in_chan=%d range length=%d\n",
i, chanlist[i], s->n_chan,
s->range_table->length);
return -EINVAL;
}
} else if (s->range_table_list) {
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
chan = CR_CHAN(chanlist[i]); chanspec = chanlist[i];
chan = CR_CHAN(chanspec);
if (s->range_table)
range_len = s->range_table->length;
else if (s->range_table_list && chan < s->n_chan)
range_len = s->range_table_list[chan]->length;
else
range_len = 0;
if (chan >= s->n_chan || if (chan >= s->n_chan ||
CR_RANGE(chanlist[i]) >= CR_RANGE(chanspec) >= range_len ||
s->range_table_list[chan]->length aref_invalid(s, chanspec)) {
|| aref_invalid(s, chanlist[i])) {
dev_warn(dev->class_dev, dev_warn(dev->class_dev,
"bad chanlist[%d]=0x%08x\n", "bad chanlist[%d]=0x%08x chan=%d range length=%d\n",
i, chanlist[i]); i, chanspec, chan, range_len);
return -EINVAL; return -EINVAL;
} }
} }
......
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