Skip to content

Commit

Permalink
staging: comedi: dt9812: use CR_CHAN() for channel number
Browse files Browse the repository at this point in the history
commit 564c526 upstream.

As pointed out by Dan Carpenper in
<http://driverdev.linuxdriverproject.org/pipermail/devel/2013-February/036025.html>,
the dt9812 comedi driver's use of the `chanspec` member of `struct
comedi_insn` as a channel number is incorrect.  Change it to use
`CR_CHAN(insn->chanspec)` as the channel number (where `insn` is a
pointer to the `struct comedi_insn` being processed).

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Anders Blomdell <anders.blomdell@control.lth.se>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Ian Abbott authored and Greg Kroah-Hartman committed Mar 20, 2013
1 parent 6564af0 commit 79ba4d0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions drivers/staging/comedi/drivers/dt9812.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,12 +948,13 @@ static int dt9812_di_rinsn(struct comedi_device *dev,
unsigned int *data)
{
struct comedi_dt9812 *devpriv = dev->private;
unsigned int channel = CR_CHAN(insn->chanspec);
int n;
u8 bits = 0;

dt9812_digital_in(devpriv->slot, &bits);
for (n = 0; n < insn->n; n++)
data[n] = ((1 << insn->chanspec) & bits) != 0;
data[n] = ((1 << channel) & bits) != 0;
return n;
}

Expand All @@ -962,12 +963,13 @@ static int dt9812_do_winsn(struct comedi_device *dev,
unsigned int *data)
{
struct comedi_dt9812 *devpriv = dev->private;
unsigned int channel = CR_CHAN(insn->chanspec);
int n;
u8 bits = 0;

dt9812_digital_out_shadow(devpriv->slot, &bits);
for (n = 0; n < insn->n; n++) {
u8 mask = 1 << insn->chanspec;
u8 mask = 1 << channel;

bits &= ~mask;
if (data[n])
Expand All @@ -982,13 +984,13 @@ static int dt9812_ai_rinsn(struct comedi_device *dev,
unsigned int *data)
{
struct comedi_dt9812 *devpriv = dev->private;
unsigned int channel = CR_CHAN(insn->chanspec);
int n;

for (n = 0; n < insn->n; n++) {
u16 value = 0;

dt9812_analog_in(devpriv->slot, insn->chanspec, &value,
DT9812_GAIN_1);
dt9812_analog_in(devpriv->slot, channel, &value, DT9812_GAIN_1);
data[n] = value;
}
return n;
Expand All @@ -999,12 +1001,13 @@ static int dt9812_ao_rinsn(struct comedi_device *dev,
unsigned int *data)
{
struct comedi_dt9812 *devpriv = dev->private;
unsigned int channel = CR_CHAN(insn->chanspec);
int n;
u16 value;

for (n = 0; n < insn->n; n++) {
value = 0;
dt9812_analog_out_shadow(devpriv->slot, insn->chanspec, &value);
dt9812_analog_out_shadow(devpriv->slot, channel, &value);
data[n] = value;
}
return n;
Expand All @@ -1015,10 +1018,11 @@ static int dt9812_ao_winsn(struct comedi_device *dev,
unsigned int *data)
{
struct comedi_dt9812 *devpriv = dev->private;
unsigned int channel = CR_CHAN(insn->chanspec);
int n;

for (n = 0; n < insn->n; n++)
dt9812_analog_out(devpriv->slot, insn->chanspec, data[n]);
dt9812_analog_out(devpriv->slot, channel, data[n]);
return n;
}

Expand Down

0 comments on commit 79ba4d0

Please sign in to comment.