From: Arnd Bergmann Date: Tue, 25 Oct 2016 15:55:04 +0000 (+0200) Subject: iio: maxim_thermocouple: detect invalid storage size in read() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=32cb7d27e65d;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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: 231147ee77f3 ("iio: maxim_thermocouple: Align 16 bit big endian value of raw reads") Signed-off-by: Arnd Bergmann Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c index 39dd2026ccc9..d19a4dea4c3c 100644 --- a/drivers/iio/temperature/maxim_thermocouple.c +++ b/drivers/iio/temperature/maxim_thermocouple.c @@ -137,6 +137,8 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data, case 4: *val = be32_to_cpu(buf); break; + default: + ret = -EINVAL; } /* check to be sure this is a valid reading */