提交 d70674ee 编写于 作者: A Arnd Bergmann 提交者: Greg Kroah-Hartman

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: 231147ee ("iio: maxim_thermocouple: Align 16 bit big endian value of raw reads")
Signed-off-by: NArnd Bergmann <arnd@arndb.de>
Signed-off-by: NJonathan Cameron <jic23@kernel.org>
(cherry picked from commit 32cb7d27)
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 68fae2f3
......@@ -136,6 +136,8 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
*val = be32_to_cpu(buf32);
break;
default:
ret = -EINVAL;
}
if (ret)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册