All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>
Cc: linux-arm-kernel@lists.infradead.org,
	Hartmut Knaack <knaack.h@gmx.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-iio@vger.kernel.org, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: ade7753: avoid uninitialized data
Date: Sat, 30 Jan 2016 14:22:10 +0000	[thread overview]
Message-ID: <56ACC712.1020402@kernel.org> (raw)
In-Reply-To: <1453737174-1959778-1-git-send-email-arnd@arndb.de>

On 25/01/16 15:52, Arnd Bergmann wrote:
> The ade7753_spi_read_reg_16() will either successfully read a value
> from SPI, or return a failure code without delivering data. However,
> the ade7753_stop_device() and ade7753_reset() functions use the returned
> data without checking for an error condition first. Gcc detects this
> as a possible bug and warns about it:
> 
> drivers/staging/iio/meter/ade7753.c: In function 'ade7753_remove':
> drivers/staging/iio/meter/ade7753.c:348:6: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>   val |= BIT(4);  /* AD converters can be turned off */
>       ^
> drivers/staging/iio/meter/ade7753.c:345:6: note: 'val' was declared here
>   u16 val;
>       ^
> drivers/staging/iio/meter/ade7753.c: In function 'ade7753_probe':
> drivers/staging/iio/meter/ade7753.c:222:6: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> In both cases, we can avoids the warning by checking the return code
> before using the data.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Thanks.

Applied to the togreg branch of iio.git - initially pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/staging/iio/meter/ade7753.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c
> index f129039bece3..69287108f793 100644
> --- a/drivers/staging/iio/meter/ade7753.c
> +++ b/drivers/staging/iio/meter/ade7753.c
> @@ -217,8 +217,12 @@ error_ret:
>  static int ade7753_reset(struct device *dev)
>  {
>  	u16 val;
> +	int ret;
> +
> +	ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
> +	if (ret)
> +		return ret;
>  
> -	ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
>  	val |= BIT(6); /* Software Chip Reset */
>  
>  	return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val);
> @@ -343,8 +347,12 @@ error_ret:
>  static int ade7753_stop_device(struct device *dev)
>  {
>  	u16 val;
> +	int ret;
> +
> +	ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
> +	if (ret)
> +		return ret;
>  
> -	ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
>  	val |= BIT(4);  /* AD converters can be turned off */
>  
>  	return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val);
> 


WARNING: multiple messages have this Message-ID (diff)
From: jic23@kernel.org (Jonathan Cameron)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] iio: ade7753: avoid uninitialized data
Date: Sat, 30 Jan 2016 14:22:10 +0000	[thread overview]
Message-ID: <56ACC712.1020402@kernel.org> (raw)
In-Reply-To: <1453737174-1959778-1-git-send-email-arnd@arndb.de>

On 25/01/16 15:52, Arnd Bergmann wrote:
> The ade7753_spi_read_reg_16() will either successfully read a value
> from SPI, or return a failure code without delivering data. However,
> the ade7753_stop_device() and ade7753_reset() functions use the returned
> data without checking for an error condition first. Gcc detects this
> as a possible bug and warns about it:
> 
> drivers/staging/iio/meter/ade7753.c: In function 'ade7753_remove':
> drivers/staging/iio/meter/ade7753.c:348:6: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>   val |= BIT(4);  /* AD converters can be turned off */
>       ^
> drivers/staging/iio/meter/ade7753.c:345:6: note: 'val' was declared here
>   u16 val;
>       ^
> drivers/staging/iio/meter/ade7753.c: In function 'ade7753_probe':
> drivers/staging/iio/meter/ade7753.c:222:6: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> In both cases, we can avoids the warning by checking the return code
> before using the data.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Thanks.

Applied to the togreg branch of iio.git - initially pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/staging/iio/meter/ade7753.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c
> index f129039bece3..69287108f793 100644
> --- a/drivers/staging/iio/meter/ade7753.c
> +++ b/drivers/staging/iio/meter/ade7753.c
> @@ -217,8 +217,12 @@ error_ret:
>  static int ade7753_reset(struct device *dev)
>  {
>  	u16 val;
> +	int ret;
> +
> +	ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
> +	if (ret)
> +		return ret;
>  
> -	ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
>  	val |= BIT(6); /* Software Chip Reset */
>  
>  	return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val);
> @@ -343,8 +347,12 @@ error_ret:
>  static int ade7753_stop_device(struct device *dev)
>  {
>  	u16 val;
> +	int ret;
> +
> +	ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
> +	if (ret)
> +		return ret;
>  
> -	ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
>  	val |= BIT(4);  /* AD converters can be turned off */
>  
>  	return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val);
> 

  reply	other threads:[~2016-01-30 14:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-25 15:52 [PATCH] iio: ade7753: avoid uninitialized data Arnd Bergmann
2016-01-25 15:52 ` Arnd Bergmann
2016-01-30 14:22 ` Jonathan Cameron [this message]
2016-01-30 14:22   ` Jonathan Cameron

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=56ACC712.1020402@kernel.org \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=arnd@arndb.de \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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 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.