[PATCH 1/2] staging: comedi: rtd520: fix ai_read_n() async->cur_chan use

H Hartley Sweeten hsweeten at visionengravers.com
Thu Oct 30 18:32:28 UTC 2014


This functions uses the async->cur_chan to determine if the current channel
is using a bipolar range and the sample needs to be munged. The cur_chan is
never incremented so all the samples are munged based on the fist channel
in the cmd->chanlist.

Bump the cur_chan after writing each sample. This fixes the code so that
the munging will be done correctly.

Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
Cc: Ian Abbott <abbotti at mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
---
 drivers/staging/comedi/drivers/rtd520.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c
index 888238e..8e87655 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -606,6 +606,8 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
 		     int count)
 {
 	struct rtd_private *devpriv = dev->private;
+	struct comedi_async *async = s->async;
+	struct comedi_cmd *cmd = &async->cmd;
 	int ii;
 
 	for (ii = 0; ii < count; ii++) {
@@ -618,7 +620,7 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
 
 		d = readw(devpriv->las1 + LAS1_ADC_FIFO);
 		d = d >> 3;	/* low 3 bits are marker lines */
-		if (test_bit(s->async->cur_chan, devpriv->chan_is_bipolar))
+		if (test_bit(async->cur_chan, devpriv->chan_is_bipolar))
 			/* convert to comedi unsigned data */
 			d = comedi_offset_munge(s, d);
 		d &= s->maxdata;
@@ -626,6 +628,9 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
 		if (!comedi_buf_write_samples(s, &d, 1))
 			return -1;
 
+		async->cur_chan++;
+		async->cur_chan %= cmd->chanlist_len;
+
 		if (devpriv->ai_count > 0)	/* < 0, means read forever */
 			devpriv->ai_count--;
 	}
-- 
2.0.3



More information about the devel mailing list