Commit aabcbfe8 authored by Dan Carpenter's avatar Dan Carpenter Committed by Jonathan Cameron

iio: sca3000: Potential endian bug in sca3000_read_event_value()

The problem is that "ret" is an int but we're casting it as
"(unsigned long *)&ret" when we do the for_each_set_bit() loop.  This
will not work on big endian 64 bit systems.
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 05b8bcc9
...@@ -872,8 +872,9 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev, ...@@ -872,8 +872,9 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
enum iio_event_info info, enum iio_event_info info,
int *val, int *val2) int *val, int *val2)
{ {
int ret, i;
struct sca3000_state *st = iio_priv(indio_dev); struct sca3000_state *st = iio_priv(indio_dev);
long ret;
int i;
switch (info) { switch (info) {
case IIO_EV_INFO_VALUE: case IIO_EV_INFO_VALUE:
...@@ -885,11 +886,11 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev, ...@@ -885,11 +886,11 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
return ret; return ret;
*val = 0; *val = 0;
if (chan->channel2 == IIO_MOD_Y) if (chan->channel2 == IIO_MOD_Y)
for_each_set_bit(i, (unsigned long *)&ret, for_each_set_bit(i, &ret,
ARRAY_SIZE(st->info->mot_det_mult_y)) ARRAY_SIZE(st->info->mot_det_mult_y))
*val += st->info->mot_det_mult_y[i]; *val += st->info->mot_det_mult_y[i];
else else
for_each_set_bit(i, (unsigned long *)&ret, for_each_set_bit(i, &ret,
ARRAY_SIZE(st->info->mot_det_mult_xz)) ARRAY_SIZE(st->info->mot_det_mult_xz))
*val += st->info->mot_det_mult_xz[i]; *val += st->info->mot_det_mult_xz[i];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment