Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1508404 > unrolled thread

[PATCH] iio: maxim_thermocouple: detect invalid storage size in read()

Started byArnd Bergmann <arnd@arndb.de>
First post2016-10-25 18:00 +0200
Last post2016-10-25 18:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] iio: maxim_thermocouple: detect invalid storage size in read() Arnd Bergmann <arnd@arndb.de> - 2016-10-25 18:00 +0200
    Re: [PATCH] iio: maxim_thermocouple: detect invalid storage size in  read() Jonathan Cameron <jic23@kernel.org> - 2016-10-25 18:30 +0200

#1508404 — [PATCH] iio: maxim_thermocouple: detect invalid storage size in read()

FromArnd Bergmann <arnd@arndb.de>
Date2016-10-25 18:00 +0200
Subject[PATCH] iio: maxim_thermocouple: detect invalid storage size in read()
Message-ID<swciX-7zc-25@gated-at.bofh.it>
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 <arnd@arndb.de>
---
 drivers/iio/temperature/maxim_thermocouple.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index 066161a4bccd..f962f31a5eb2 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -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)
-- 
2.9.0

[toc] | [next] | [standalone]


#1508417 — Re: [PATCH] iio: maxim_thermocouple: detect invalid storage size in read()

FromJonathan Cameron <jic23@kernel.org>
Date2016-10-25 18:30 +0200
SubjectRe: [PATCH] iio: maxim_thermocouple: detect invalid storage size in read()
Message-ID<swcLT-83d-1@gated-at.bofh.it>
In reply to#1508404
On 25/10/16 16:55, Arnd Bergmann wrote:
> 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.
Agreed on all counts.
> 
> Fixes: 231147ee77f3 ("iio: maxim_thermocouple: Align 16 bit big endian value of raw reads")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Applied to the togreg branch of iio.git. Initially pushed out as testing for the
autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/temperature/maxim_thermocouple.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
> index 066161a4bccd..f962f31a5eb2 100644
> --- a/drivers/iio/temperature/maxim_thermocouple.c
> +++ b/drivers/iio/temperature/maxim_thermocouple.c
> @@ -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)
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web