All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: maxim_thermocouple: detect invalid storage size in read()
@ 2016-10-25 15:55 Arnd Bergmann
  2016-10-25 16:29 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2016-10-25 15:55 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Arnd Bergmann, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Matt Ranostay, sayli karnik, Wei Yongjun,
	linux-iio, linux-kernel

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: maxim_thermocouple: detect invalid storage size in read()
  2016-10-25 15:55 [PATCH] iio: maxim_thermocouple: detect invalid storage size in read() Arnd Bergmann
@ 2016-10-25 16:29 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2016-10-25 16:29 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Matt Ranostay, sayli karnik, Wei Yongjun, linux-iio,
	linux-kernel

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)
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-25 16:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-25 15:55 [PATCH] iio: maxim_thermocouple: detect invalid storage size in read() Arnd Bergmann
2016-10-25 16:29 ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.