Skip to content

Commit 2fdac5e

Browse files
Dan Carpenterehristev
authored andcommitted
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: 23ec277 ("iio: adc: at91-sama5d2_adc: add support for position and pressure channels") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Tested-by: Eugen Hristev <eugen.hristev@microchip.com> Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 70245dd commit 2fdac5e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

drivers/iio/adc/at91-sama5d2_adc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
12961296
{
12971297
struct at91_adc_state *st = iio_priv(indio_dev);
12981298
u32 cor = 0;
1299+
u16 tmp_val;
12991300
int ret;
13001301

13011302
/*
@@ -1309,7 +1310,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
13091310
mutex_lock(&st->lock);
13101311

13111312
ret = at91_adc_read_position(st, chan->channel,
1312-
(u16 *)val);
1313+
&tmp_val);
1314+
*val = tmp_val;
13131315
mutex_unlock(&st->lock);
13141316
iio_device_release_direct_mode(indio_dev);
13151317

@@ -1322,7 +1324,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
13221324
mutex_lock(&st->lock);
13231325

13241326
ret = at91_adc_read_pressure(st, chan->channel,
1325-
(u16 *)val);
1327+
&tmp_val);
1328+
*val = tmp_val;
13261329
mutex_unlock(&st->lock);
13271330
iio_device_release_direct_mode(indio_dev);
13281331

0 commit comments

Comments
 (0)