linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Matt Ranostay <mranostay@gmail.com>,
	sayli karnik <karniksayli1995@gmail.com>,
	Wei Yongjun <weiyongjun1@huawei.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: maxim_thermocouple: detect invalid storage size in read()
Date: Tue, 25 Oct 2016 17:29:27 +0100	[thread overview]
Message-ID: <049cdec2-67c5-3311-83b7-d9d7e2779ce8@kernel.org> (raw)
In-Reply-To: <20161025155538.38037-1-arnd@arndb.de>

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


      reply	other threads:[~2016-10-25 16:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=049cdec2-67c5-3311-83b7-d9d7e2779ce8@kernel.org \
    --to=jic23@kernel.org \
    --cc=arnd@arndb.de \
    --cc=karniksayli1995@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mranostay@gmail.com \
    --cc=pmeerw@pmeerw.net \
    --cc=weiyongjun1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).