Skip to content

Commit 231147e

Browse files
Sayli-Karnikjic23
authored andcommitted
iio: maxim_thermocouple: Align 16 bit big endian value of raw reads
Driver was reporting invalid raw read values for MAX6675 on big endian architectures. MAX6675 buffered mode is not affected, nor is the MAX31855. The driver was losing a 2 byte read value when it used a 32 bit integer buffer to store a 16 bit big endian value. Use big endian types to properly align buffers on big endian architectures. Fixes following sparse endianness warnings: warning: cast to restricted __be16 warning: cast to restricted __be32 Fixes checkpatch issue: CHECK: No space is necessary after a cast Signed-off-by: sayli karnik <[email protected]> Fixes: 1f25ca1 ("iio: temperature: add support for Maxim thermocouple chips") Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 0ae952e commit 231147e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/iio/temperature/maxim_thermocouple.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,24 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
123123
{
124124
unsigned int storage_bytes = data->chip->read_size;
125125
unsigned int shift = chan->scan_type.shift + (chan->address * 8);
126-
unsigned int buf;
126+
__be16 buf16;
127+
__be32 buf32;
127128
int ret;
128129

129-
ret = spi_read(data->spi, (void *) &buf, storage_bytes);
130-
if (ret)
131-
return ret;
132-
133130
switch (storage_bytes) {
134131
case 2:
135-
*val = be16_to_cpu(buf);
132+
ret = spi_read(data->spi, (void *)&buf16, storage_bytes);
133+
*val = be16_to_cpu(buf16);
136134
break;
137135
case 4:
138-
*val = be32_to_cpu(buf);
136+
ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
137+
*val = be32_to_cpu(buf32);
139138
break;
140139
}
141140

141+
if (ret)
142+
return ret;
143+
142144
/* check to be sure this is a valid reading */
143145
if (*val & data->chip->status_bit)
144146
return -EINVAL;

0 commit comments

Comments
 (0)