Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
staging: comedi: addi_apci_1500: Fix endian problem for command sample
Browse files Browse the repository at this point in the history
commit ac0bbf55ed3be75fde1f8907e91ecd2fd589bde3 upstream.

The digital input subdevice supports Comedi asynchronous commands that
read interrupt status information.  This uses 16-bit Comedi samples (of
which only the bottom 8 bits contain status information).  However, the
interrupt handler is calling `comedi_buf_write_samples()` with the
address of a 32-bit variable `unsigned int status`.  On a bigendian
machine, this will copy 2 bytes from the wrong end of the variable.  Fix
it by changing the type of the variable to `unsigned short`.

Fixes: a8c66b6 ("staging: comedi: addi_apci_1500: rewrite the subdevice support functions")
Cc: <[email protected]> #4.0+
Signed-off-by: Ian Abbott <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ian-abbott authored and gregkh committed Mar 17, 2021
1 parent 62b7367 commit 4f6ed0e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions drivers/staging/comedi/drivers/addi_apci_1500.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static irqreturn_t apci1500_interrupt(int irq, void *d)
struct comedi_device *dev = d;
struct apci1500_private *devpriv = dev->private;
struct comedi_subdevice *s = dev->read_subdev;
unsigned int status = 0;
unsigned short status = 0;
unsigned int val;

val = inl(devpriv->amcc + AMCC_OP_REG_INTCSR);
Expand Down Expand Up @@ -247,14 +247,14 @@ static irqreturn_t apci1500_interrupt(int irq, void *d)
*
* Mask Meaning
* ---------- ------------------------------------------
* 0x00000001 Event 1 has occurred
* 0x00000010 Event 2 has occurred
* 0x00000100 Counter/timer 1 has run down (not implemented)
* 0x00001000 Counter/timer 2 has run down (not implemented)
* 0x00010000 Counter 3 has run down (not implemented)
* 0x00100000 Watchdog has run down (not implemented)
* 0x01000000 Voltage error
* 0x10000000 Short-circuit error
* 0b00000001 Event 1 has occurred
* 0b00000010 Event 2 has occurred
* 0b00000100 Counter/timer 1 has run down (not implemented)
* 0b00001000 Counter/timer 2 has run down (not implemented)
* 0b00010000 Counter 3 has run down (not implemented)
* 0b00100000 Watchdog has run down (not implemented)
* 0b01000000 Voltage error
* 0b10000000 Short-circuit error
*/
comedi_buf_write_samples(s, &status, 1);
comedi_handle_events(dev, s);
Expand Down

0 comments on commit 4f6ed0e

Please sign in to comment.