Staging: iio: fix endian conversion in ad7298_scan_direct()
Subsystems (5)
PATCH 1/1 Staging: iio: fix endian conversion in ad7298_scan_direct()
"tmp" is used to store the output from cpu_to_be16() so it should be a __be16 bit type.
---
Static checker patch. Untested.
drivers/staging/iio/adc/ad7298_core.c +7 -6
@@ -69,27 +69,28 @@ static int ad7298_scan_direct(struct ad7298_state *st, unsigned ch)static int ad7298_scan_temp (struct ad7298_state *st,int *val) {int tmp, ret; +__be16 buf; - tmp =cpu_to_be16 (AD7298_WRITE |AD7298_TSENSE | + buf =cpu_to_be16 (AD7298_WRITE |AD7298_TSENSE |AD7298_TAVG | st->ext_ref); - ret =spi_write (st->spi, (u8 *)&tmp,2 ); + ret =spi_write (st->spi, (u8 *)&buf,2 );if (ret)return ret; - tmp =0 ; + buf =cpu_to_be16 (0 ); - ret =spi_write (st->spi, (u8 *)&tmp,2 ); + ret =spi_write (st->spi, (u8 *)&buf,2 );if (ret)return ret;usleep_range (101 ,1000 );/* sleep > 100us */ - ret =spi_read (st->spi, (u8 *)&tmp,2 ); + ret =spi_read (st->spi, (u8 *)&buf,2 );if (ret)return ret; - tmp =be16_to_cpu (tmp) &RES_MASK (AD7298_BITS ); + tmp =be16_to_cpu (buf) &RES_MASK (AD7298_BITS );/* * One LSB of the ADC corresponds to 0.25 deg C.
RE: [patch] Staging: iio: fix endian conversion in
Dan Carpenter wrote on 2011-11-22:
Quoted 4 lines
"tmp" is used to store the output from
cpu_to_be16()so it should be a__be16bit type.Signed-off-by Dan Carpenter <[email protected]>
Good catch - Thanks!
Quoted 27 lines
---
Static checker patch. Untested.(quoted diff) +0
-0
b/drivers/staging/iio/adc/ad7298_core.cindex a799bd1..3e804e2 100644 ---a/drivers/staging/iio/adc/ad7298_core.c+++b/drivers/staging/iio/adc/ad7298_core.c@@ -69,27 +69,28 @@ static intad7298_scan_direct(struct ad7298_state *st, unsigned ch)
static intad7298_scan_temp(struct ad7298_state *st, int *val){ int
tmp, ret;drivers/staging/iio/adc/ad7298_core.c +5
-4+__be16 buf; - tmp =cpu_to_be16 (AD7298_WRITE |AD7298_TSENSE | + buf =cpu_to_be16 (AD7298_WRITE |AD7298_TSENSE |AD7298_TAVG | st->ext_ref); - ret =spi_write (st->spi, (u8 *)&tmp,2 ); + ret =spi_write (st->spi, (u8 *)&buf,2 );if (ret)return ret; - tmp =0 ; + buf =cpu_to_be16 (0 ); - ret =spi_write (st->spi, (u8 *)&tmp,2 ); + ret =spi_write (st->spi, (u8 *)&buf,2 );if (ret)return ret;
drivers/staging/iio/adc/ad7298_core.c static int ad7298_scan_direct(struct ad7298_state *st, unsigned ch) · line 96
Quoted 10 lines
drivers/staging/iio/adc/ad7298_core.c +2
-2usleep_range (101 ,1000 );/* sleep > 100us */ - ret =spi_read (st->spi, (u8 *)&tmp,2 ); + ret =spi_read (st->spi, (u8 *)&buf,2 );if (ret)return ret; - tmp =be16_to_cpu (tmp) &RES_MASK (AD7298_BITS ); + tmp =be16_to_cpu (buf) &RES_MASK (AD7298_BITS );/* * One LSB of the ADC corresponds to 0.25 deg C.
Greetings,
Michael
--
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif