Skip to content

Commit

Permalink
staging: comedi: adv_pci1710: Fix endian problem for AI command data
Browse files Browse the repository at this point in the history
commit b2e7863 upstream.

The analog input subdevice supports Comedi asynchronous commands that
use Comedi's 16-bit sample format.  However, the calls to
`comedi_buf_write_samples()` are passing the address of a 32-bit integer
variable.  On bigendian machines, this will copy 2 bytes from the wrong
end of the 32-bit value.  Fix it by changing the type of the variables
holding the sample value to `unsigned short`.  The type of the `val`
parameter of `pci1710_ai_read_sample()` is changed to `unsigned short *`
accordingly.  The type of the `val` variable in `pci1710_ai_insn_read()`
is also changed to `unsigned short` since its address is passed to
`pci1710_ai_read_sample()`.

Fixes: a9c3a01 ("staging: comedi: adv_pci1710: use comedi_buf_write_samples()")
Cc: <stable@vger.kernel.org> # 4.0+
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20210223143055.257402-4-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
ian-abbott authored and gregkh committed Mar 17, 2021
1 parent 66a44ed commit b46f690
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/staging/comedi/drivers/adv_pci1710.c
Expand Up @@ -300,11 +300,11 @@ static int pci1710_ai_eoc(struct comedi_device *dev,
static int pci1710_ai_read_sample(struct comedi_device *dev,
struct comedi_subdevice *s,
unsigned int cur_chan,
unsigned int *val)
unsigned short *val)
{
const struct boardtype *board = dev->board_ptr;
struct pci1710_private *devpriv = dev->private;
unsigned int sample;
unsigned short sample;
unsigned int chan;

sample = inw(dev->iobase + PCI171X_AD_DATA_REG);
Expand Down Expand Up @@ -345,7 +345,7 @@ static int pci1710_ai_insn_read(struct comedi_device *dev,
pci1710_ai_setup_chanlist(dev, s, &insn->chanspec, 1, 1);

for (i = 0; i < insn->n; i++) {
unsigned int val;
unsigned short val;

/* start conversion */
outw(0, dev->iobase + PCI171X_SOFTTRG_REG);
Expand Down Expand Up @@ -395,7 +395,7 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
{
struct comedi_cmd *cmd = &s->async->cmd;
unsigned int status;
unsigned int val;
unsigned short val;
int ret;

status = inw(dev->iobase + PCI171X_STATUS_REG);
Expand Down Expand Up @@ -455,7 +455,7 @@ static void pci1710_handle_fifo(struct comedi_device *dev,
}

for (i = 0; i < devpriv->max_samples; i++) {
unsigned int val;
unsigned short val;
int ret;

ret = pci1710_ai_read_sample(dev, s, s->async->cur_chan, &val);
Expand Down

0 comments on commit b46f690

Please sign in to comment.