From: Dan Carpenter Date: Fri, 21 Jun 2019 09:18:28 +0000 (+0300) Subject: iio: sca3000: Potential endian bug in sca3000_read_event_value() X-Git-Tag: v5.4-rc1~602^2~38^2~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aabcbfe8dbbfa87f353071182d9bbc68d10f728e;p=platform%2Fkernel%2Flinux-rpi.git 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: Dan Carpenter Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c index 4964561..9e9f434 100644 --- a/drivers/iio/accel/sca3000.c +++ b/drivers/iio/accel/sca3000.c @@ -872,8 +872,9 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev, enum iio_event_info info, int *val, int *val2) { - int ret, i; struct sca3000_state *st = iio_priv(indio_dev); + long ret; + int i; switch (info) { case IIO_EV_INFO_VALUE: @@ -885,11 +886,11 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev, return ret; *val = 0; 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)) *val += st->info->mot_det_mult_y[i]; else - for_each_set_bit(i, (unsigned long *)&ret, + for_each_set_bit(i, &ret, ARRAY_SIZE(st->info->mot_det_mult_xz)) *val += st->info->mot_det_mult_xz[i];