aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorsayli karnik <karniksayli1995@gmail.com>2016-09-28 12:16:51 -0400
committerJonathan Cameron <jic23@kernel.org>2016-10-01 09:40:23 -0400
commit231147ee77f39f4134935686e9d7e415bdf48149 (patch)
treeab5c5dfbac3a3c44cecc4dbe6a2134f39bd6a31c /drivers/iio
parent0ae952e3bd1c761d4952c8ff1a259292e4f03e89 (diff)
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 <karniksayli1995@gmail.com> Fixes: 1f25ca11d84a ("iio: temperature: add support for Maxim thermocouple chips") Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/temperature/maxim_thermocouple.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index 39dd2026ccc9..066161a4bccd 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -123,22 +123,24 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
123{ 123{
124 unsigned int storage_bytes = data->chip->read_size; 124 unsigned int storage_bytes = data->chip->read_size;
125 unsigned int shift = chan->scan_type.shift + (chan->address * 8); 125 unsigned int shift = chan->scan_type.shift + (chan->address * 8);
126 unsigned int buf; 126 __be16 buf16;
127 __be32 buf32;
127 int ret; 128 int ret;
128 129
129 ret = spi_read(data->spi, (void *) &buf, storage_bytes);
130 if (ret)
131 return ret;
132
133 switch (storage_bytes) { 130 switch (storage_bytes) {
134 case 2: 131 case 2:
135 *val = be16_to_cpu(buf); 132 ret = spi_read(data->spi, (void *)&buf16, storage_bytes);
133 *val = be16_to_cpu(buf16);
136 break; 134 break;
137 case 4: 135 case 4:
138 *val = be32_to_cpu(buf); 136 ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
137 *val = be32_to_cpu(buf32);
139 break; 138 break;
140 } 139 }
141 140
141 if (ret)
142 return ret;
143
142 /* check to be sure this is a valid reading */ 144 /* check to be sure this is a valid reading */
143 if (*val & data->chip->status_bit) 145 if (*val & data->chip->status_bit)
144 return -EINVAL; 146 return -EINVAL;