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

iio: adc: at91-sama5d2_adc: fix up casting in at91_adc_read_info_raw()

This code is problematic because we're supposed to be writing an int but
we instead write to only the high 16 bits.  This doesn't work on big
endian systems, and there is a potential that the bottom 16 bits are
used without being initialized.

Fixes: 23ec2774 ("iio: adc: at91-sama5d2_adc: add support for position and pressure channels")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Tested-by: default avatarEugen Hristev <eugen.hristev@microchip.com>
Acked-by: default avatarLudovic Desroches <ludovic.desroches@microchip.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 69f894c3
...@@ -1296,6 +1296,7 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, ...@@ -1296,6 +1296,7 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
{ {
struct at91_adc_state *st = iio_priv(indio_dev); struct at91_adc_state *st = iio_priv(indio_dev);
u32 cor = 0; u32 cor = 0;
u16 tmp_val;
int ret; int ret;
/* /*
...@@ -1309,7 +1310,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, ...@@ -1309,7 +1310,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
mutex_lock(&st->lock); mutex_lock(&st->lock);
ret = at91_adc_read_position(st, chan->channel, ret = at91_adc_read_position(st, chan->channel,
(u16 *)val); &tmp_val);
*val = tmp_val;
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
iio_device_release_direct_mode(indio_dev); iio_device_release_direct_mode(indio_dev);
...@@ -1322,7 +1324,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, ...@@ -1322,7 +1324,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
mutex_lock(&st->lock); mutex_lock(&st->lock);
ret = at91_adc_read_pressure(st, chan->channel, ret = at91_adc_read_pressure(st, chan->channel,
(u16 *)val); &tmp_val);
*val = tmp_val;
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
iio_device_release_direct_mode(indio_dev); iio_device_release_direct_mode(indio_dev);
......
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