Commit b52d8696 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: adv_pci1710: fix AI INSN_READ for non-zero channel

commit abe46b89 upstream.

Reading of analog input channels by the `INSN_READ` comedi instruction
is broken for all except channel 0.  `pci171x_ai_insn_read()` calls
`pci171x_ai_read_sample()` with the wrong value for the third parameter.
It is supposed to be the current index in a channel list (which is
always of length 1 in this case, so the index should be 0), but instead
it is passing the actual channel number.  `pci171x_ai_read_sample()`
checks the channel number encoded in the raw sample value read from the
hardware matches the channel number stored in the specified index of the
previously set up channel list and returns `-ENODATA` if it doesn't
match.  Since the index should always be 0 in this case, the match will
fail unless the channel number is also 0.  Fix it by passing 0 as the
channel index.

Note that when the bug first appeared, it was `pci171x_ai_dropout()`
that was called with the wrong parameter value.  `pci171x_ai_dropout()`
got replaced with `pci171x_ai_read_sample()` in commit 7fd2dae2
("staging: comedi: adv_pci1710: introduce pci171x_ai_read_sample()").

Fixes: 16c7eb60 ("staging: comedi: adv_pci1710: always enable PCI171x_PARANOIDCHECK code")
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1b413722
...@@ -455,7 +455,6 @@ static int pci171x_insn_read_ai(struct comedi_device *dev, ...@@ -455,7 +455,6 @@ static int pci171x_insn_read_ai(struct comedi_device *dev,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
struct pci1710_private *devpriv = dev->private; struct pci1710_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
int ret = 0; int ret = 0;
int i; int i;
...@@ -477,7 +476,7 @@ static int pci171x_insn_read_ai(struct comedi_device *dev, ...@@ -477,7 +476,7 @@ static int pci171x_insn_read_ai(struct comedi_device *dev,
break; break;
val = inw(dev->iobase + PCI171x_AD_DATA); val = inw(dev->iobase + PCI171x_AD_DATA);
ret = pci171x_ai_dropout(dev, s, chan, val); ret = pci171x_ai_dropout(dev, s, 0, val);
if (ret) if (ret)
break; break;
......
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