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

staging: comedi: adv_pci1710: don't check the chanlist twice

The chanlist is checked in Step 5 of the (*do_cmdtest) there is no
reason to check it again in the (*do_cmd). The only reason its done
again is to get the actual 'seglen', the non-repeating length of the
chanlist.

Save the 'seglen' found by pci171x_ai_check_chanlist() in the private
data and use that in the (*do_cmd). Rename the private data member to
clarify it. Also, remove the unused 'act_chanlist_pos' member from the
private data.

Refactor the error handling in pci171x_ai_check_chanlist() so it returns
and errno for failure and 0 for success.
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 b5a7a466
...@@ -310,8 +310,7 @@ struct pci1710_private { ...@@ -310,8 +310,7 @@ struct pci1710_private {
unsigned int ai_et_MuxVal; unsigned int ai_et_MuxVal;
unsigned int ai_et_div1, ai_et_div2; unsigned int ai_et_div1, ai_et_div2;
unsigned int act_chanlist[32]; /* list of scanned channel */ unsigned int act_chanlist[32]; /* list of scanned channel */
unsigned char act_chanlist_len; /* len of scanlist */ unsigned char saved_seglen; /* len of the non-repeating chanlist */
unsigned char act_chanlist_pos; /* actual position in MUX list */
unsigned char da_ranges; /* copy of D/A outpit range register */ unsigned char da_ranges; /* copy of D/A outpit range register */
unsigned short ao_data[4]; /* data output buffer */ unsigned short ao_data[4]; /* data output buffer */
unsigned int cnt0_write_wait; /* after a write, wait for update of the unsigned int cnt0_write_wait; /* after a write, wait for update of the
...@@ -330,6 +329,7 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev, ...@@ -330,6 +329,7 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_cmd *cmd) struct comedi_cmd *cmd)
{ {
struct pci1710_private *devpriv = dev->private;
unsigned int chan0 = CR_CHAN(cmd->chanlist[0]); unsigned int chan0 = CR_CHAN(cmd->chanlist[0]);
unsigned int last_aref = CR_AREF(cmd->chanlist[0]); unsigned int last_aref = CR_AREF(cmd->chanlist[0]);
unsigned int next_chan = (chan0 + 1) % s->n_chan; unsigned int next_chan = (chan0 + 1) % s->n_chan;
...@@ -337,8 +337,10 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev, ...@@ -337,8 +337,10 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev,
unsigned int seglen; unsigned int seglen;
int i; int i;
if (cmd->chanlist_len == 1) if (cmd->chanlist_len == 1) {
return 1; /* seglen=1 */ devpriv->saved_seglen = cmd->chanlist_len;
return 0;
}
/* first channel is always ok */ /* first channel is always ok */
chansegment[0] = cmd->chanlist[0]; chansegment[0] = cmd->chanlist[0];
...@@ -353,7 +355,7 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev, ...@@ -353,7 +355,7 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev,
if (aref == AREF_DIFF && (chan & 1)) { if (aref == AREF_DIFF && (chan & 1)) {
dev_err(dev->class_dev, dev_err(dev->class_dev,
"Odd channel cannot be differential input!\n"); "Odd channel cannot be differential input!\n");
return 0; return -EINVAL;
} }
if (last_aref == AREF_DIFF) if (last_aref == AREF_DIFF)
...@@ -362,7 +364,7 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev, ...@@ -362,7 +364,7 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev,
dev_err(dev->class_dev, dev_err(dev->class_dev,
"channel list must be continuous! chanlist[%i]=%d but must be %d or %d!\n", "channel list must be continuous! chanlist[%i]=%d but must be %d or %d!\n",
i, chan, next_chan, chan0); i, chan, next_chan, chan0);
return 0; return -EINVAL;
} }
/* next correct channel in list */ /* next correct channel in list */
...@@ -381,10 +383,12 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev, ...@@ -381,10 +383,12 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev,
CR_CHAN(cmd->chanlist[i % seglen]), CR_CHAN(cmd->chanlist[i % seglen]),
CR_RANGE(cmd->chanlist[i % seglen]), CR_RANGE(cmd->chanlist[i % seglen]),
CR_AREF(chansegment[i % seglen])); CR_AREF(chansegment[i % seglen]));
return 0; return -EINVAL;
} }
} }
return seglen; devpriv->saved_seglen = seglen;
return 0;
} }
static void setup_channel_list(struct comedi_device *dev, static void setup_channel_list(struct comedi_device *dev,
...@@ -396,9 +400,6 @@ static void setup_channel_list(struct comedi_device *dev, ...@@ -396,9 +400,6 @@ static void setup_channel_list(struct comedi_device *dev,
struct pci1710_private *devpriv = dev->private; struct pci1710_private *devpriv = dev->private;
unsigned int i, range, chanprog; unsigned int i, range, chanprog;
devpriv->act_chanlist_len = seglen;
devpriv->act_chanlist_pos = 0;
for (i = 0; i < seglen; i++) { /* store range list to card */ for (i = 0; i < seglen; i++) { /* store range list to card */
chanprog = muxonechan[CR_CHAN(chanlist[i])]; chanprog = muxonechan[CR_CHAN(chanlist[i])];
outw(chanprog, dev->iobase + PCI171x_MUX); /* select channel */ outw(chanprog, dev->iobase + PCI171x_MUX); /* select channel */
...@@ -953,7 +954,6 @@ static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -953,7 +954,6 @@ static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
struct pci1710_private *devpriv = dev->private; struct pci1710_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd; struct comedi_cmd *cmd = &s->async->cmd;
unsigned int divisor1 = 0, divisor2 = 0; unsigned int divisor1 = 0, divisor2 = 0;
unsigned int seglen;
int mode; int mode;
if (cmd->convert_src == TRIG_TIMER) { if (cmd->convert_src == TRIG_TIMER) {
...@@ -967,10 +967,8 @@ static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -967,10 +967,8 @@ static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
start_pacer(dev, -1, 0, 0); /* stop pacer */ start_pacer(dev, -1, 0, 0); /* stop pacer */
seglen = pci171x_ai_check_chanlist(dev, s, cmd); setup_channel_list(dev, s, cmd->chanlist, cmd->chanlist_len,
if (seglen < 1) devpriv->saved_seglen);
return -EINVAL;
setup_channel_list(dev, s, cmd->chanlist, cmd->chanlist_len, seglen);
outb(0, dev->iobase + PCI171x_CLRFIFO); outb(0, dev->iobase + PCI171x_CLRFIFO);
outb(0, dev->iobase + PCI171x_CLRINT); outb(0, dev->iobase + PCI171x_CLRINT);
...@@ -1104,7 +1102,9 @@ static int pci171x_ai_cmdtest(struct comedi_device *dev, ...@@ -1104,7 +1102,9 @@ static int pci171x_ai_cmdtest(struct comedi_device *dev,
/* Step 5: check channel list */ /* Step 5: check channel list */
if (!pci171x_ai_check_chanlist(dev, s, cmd)) err |= pci171x_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