Skip to content

Commit

Permalink
staging: comedi: usbduxsigma: fix unaligned dereferences
Browse files Browse the repository at this point in the history
There are a couple of dereferences such as `*(uint32_t
*)(devpriv->insn_buf + 1)` that are unaligned as `devpriv->insn_buf` is
of type `uint8_t *`.  This works on x86 architecture but may not be
supported on other architectures.  Call `get_unalign()` to perform the
unaligned dereferences.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Cc: Bernd Porr <mail@berndporr.me.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Ian Abbott authored and Greg Kroah-Hartman committed Feb 7, 2014
1 parent f1ffdfc commit 791771e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/staging/comedi/drivers/usbduxsigma.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <linux/usb.h>
#include <linux/fcntl.h>
#include <linux/compiler.h>
#include <asm/unaligned.h>

#include "comedi_fc.h"
#include "../comedidev.h"
Expand Down Expand Up @@ -792,7 +793,8 @@ static int usbduxsigma_ai_insn_read(struct comedi_device *dev,
}

/* 32 bits big endian from the A/D converter */
val = be32_to_cpu(*((uint32_t *)((devpriv->insn_buf) + 1)));
val = be32_to_cpu(get_unaligned((uint32_t
*)(devpriv->insn_buf + 1)));
val &= 0x00ffffff; /* strip status byte */
val ^= 0x00800000; /* convert to unsigned */

Expand Down Expand Up @@ -1357,7 +1359,7 @@ static int usbduxsigma_getstatusinfo(struct comedi_device *dev, int chan)
return ret;

/* 32 bits big endian from the A/D converter */
val = be32_to_cpu(*((uint32_t *)((devpriv->insn_buf)+1)));
val = be32_to_cpu(get_unaligned((uint32_t *)(devpriv->insn_buf + 1)));
val &= 0x00ffffff; /* strip status byte */
val ^= 0x00800000; /* convert to unsigned */

Expand Down

0 comments on commit 791771e

Please sign in to comment.