Skip to content

Commit d70674e

Browse files
arndbgregkh
authored andcommitted
iio: maxim_thermocouple: detect invalid storage size in read()
As found by gcc -Wmaybe-uninitialized, having a storage_bytes value other than 2 or 4 will result in undefined behavior: drivers/iio/temperature/maxim_thermocouple.c: In function 'maxim_thermocouple_read': drivers/iio/temperature/maxim_thermocouple.c:141:5: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized] This probably cannot happen, but returning -EINVAL here is appropriate and makes gcc happy and the code more robust. Fixes: 231147e ("iio: maxim_thermocouple: Align 16 bit big endian value of raw reads") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]> (cherry picked from commit 32cb7d2) Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 68fae2f commit d70674e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/iio/temperature/maxim_thermocouple.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
136136
ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
137137
*val = be32_to_cpu(buf32);
138138
break;
139+
default:
140+
ret = -EINVAL;
139141
}
140142

141143
if (ret)

0 commit comments

Comments
 (0)