aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2014-02-05 16:59:53 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-02-07 12:19:30 -0500
commit1e85c1ea1ff2a60659e790ef8ec76c7339445841 (patch)
tree51c6dd096c24edffeb9341f2a30a7cb97e379960
parent7a081ea20e043f243b6fb9d50448cbe757fbb860 (diff)
staging: comedi: adv_pci1710: fix analog output readback value
The last value written to a analog output channel is cached in the private data of this driver for readback. Currently, the wrong value is cached in the (*insn_write) functions. The current code stores the data[n] value for readback afer the loop has written all the values. At this time 'n' points past the end of the data array. Fix the functions by using a local variable to hold the data being written to the analog output channel. This variable is then used after the loop is complete to store the readback value. The current value is retrieved before the loop in case no values are actually written.. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1710.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index 593676cf706a..d9ad2c0fdda2 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -494,6 +494,7 @@ static int pci171x_insn_write_ao(struct comedi_device *dev,
494 struct comedi_insn *insn, unsigned int *data) 494 struct comedi_insn *insn, unsigned int *data)
495{ 495{
496 struct pci1710_private *devpriv = dev->private; 496 struct pci1710_private *devpriv = dev->private;
497 unsigned int val;
497 int n, chan, range, ofs; 498 int n, chan, range, ofs;
498 499
499 chan = CR_CHAN(insn->chanspec); 500 chan = CR_CHAN(insn->chanspec);
@@ -509,11 +510,14 @@ static int pci171x_insn_write_ao(struct comedi_device *dev,
509 outw(devpriv->da_ranges, dev->iobase + PCI171x_DAREF); 510 outw(devpriv->da_ranges, dev->iobase + PCI171x_DAREF);
510 ofs = PCI171x_DA1; 511 ofs = PCI171x_DA1;
511 } 512 }
513 val = devpriv->ao_data[chan];
512 514
513 for (n = 0; n < insn->n; n++) 515 for (n = 0; n < insn->n; n++) {
514 outw(data[n], dev->iobase + ofs); 516 val = data[n];
517 outw(val, dev->iobase + ofs);
518 }
515 519
516 devpriv->ao_data[chan] = data[n]; 520 devpriv->ao_data[chan] = val;
517 521
518 return n; 522 return n;
519 523
@@ -679,6 +683,7 @@ static int pci1720_insn_write_ao(struct comedi_device *dev,
679 struct comedi_insn *insn, unsigned int *data) 683 struct comedi_insn *insn, unsigned int *data)
680{ 684{
681 struct pci1710_private *devpriv = dev->private; 685 struct pci1710_private *devpriv = dev->private;
686 unsigned int val;
682 int n, rangereg, chan; 687 int n, rangereg, chan;
683 688
684 chan = CR_CHAN(insn->chanspec); 689 chan = CR_CHAN(insn->chanspec);
@@ -688,13 +693,15 @@ static int pci1720_insn_write_ao(struct comedi_device *dev,
688 outb(rangereg, dev->iobase + PCI1720_RANGE); 693 outb(rangereg, dev->iobase + PCI1720_RANGE);
689 devpriv->da_ranges = rangereg; 694 devpriv->da_ranges = rangereg;
690 } 695 }
696 val = devpriv->ao_data[chan];
691 697
692 for (n = 0; n < insn->n; n++) { 698 for (n = 0; n < insn->n; n++) {
693 outw(data[n], dev->iobase + PCI1720_DA0 + (chan << 1)); 699 val = data[n];
700 outw(val, dev->iobase + PCI1720_DA0 + (chan << 1));
694 outb(0, dev->iobase + PCI1720_SYNCOUT); /* update outputs */ 701 outb(0, dev->iobase + PCI1720_SYNCOUT); /* update outputs */
695 } 702 }
696 703
697 devpriv->ao_data[chan] = data[n]; 704 devpriv->ao_data[chan] = val;
698 705
699 return n; 706 return n;
700} 707}