Skip to content

Commit

Permalink
Staging: iio: fix endian conversion in ad7298_scan_direct()
Browse files Browse the repository at this point in the history
"tmp" is used to store the output from cpu_to_be16() so it should be
a __be16 bit type.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Dan Carpenter authored and Greg Kroah-Hartman committed Nov 27, 2011
1 parent 5ae8f44 commit c1a7528
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/staging/iio/adc/ad7298_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c1a7528

Please sign in to comment.