From: Jonathan Cameron <jic23@kernel.org>
To: trix@redhat.com
Cc: jacopo@jmondi.org, lars@metafoo.de, nathan@kernel.org,
ndesaulniers@google.com, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH] iio: chemical: set val parameter only on success
Date: Tue, 28 Dec 2021 18:39:25 +0000 [thread overview]
Message-ID: <20211228183925.059884e1@jic23-huawei> (raw)
In-Reply-To: <20211224150833.3278236-1-trix@redhat.com>
On Fri, 24 Dec 2021 07:08:33 -0800
trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
>
> Clang static analysis reports this representative warning
>
> sunrise_co2.c:410:9: warning: Assigned value is garbage or undefined
> *val = value;
> ^ ~~~~~
>
> The ealier call to sunrise_read_word can fail without setting
> value. So defer setting val until we know the read was successful.
>
> Fixes: c397894e24f1 ("iio: chemical: Add Senseair Sunrise 006-0-007 driver")
> Signed-off-by: Tom Rix <trix@redhat.com>
Hi Tom,
This won't have any actual affect as if the read_raw callback returns a negative
error code we won't use the value. However, good to clean it up so applied
to the togreg branch of iio.git.
Thanks,
Jonathan
> ---
> drivers/iio/chemical/sunrise_co2.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/chemical/sunrise_co2.c b/drivers/iio/chemical/sunrise_co2.c
> index 233bd0f379c93..8440dc0c77cfe 100644
> --- a/drivers/iio/chemical/sunrise_co2.c
> +++ b/drivers/iio/chemical/sunrise_co2.c
> @@ -407,24 +407,24 @@ static int sunrise_read_raw(struct iio_dev *iio_dev,
> mutex_lock(&sunrise->lock);
> ret = sunrise_read_word(sunrise, SUNRISE_CO2_FILTERED_COMP_REG,
> &value);
> - *val = value;
> mutex_unlock(&sunrise->lock);
>
> if (ret)
> return ret;
>
> + *val = value;
> return IIO_VAL_INT;
>
> case IIO_TEMP:
> mutex_lock(&sunrise->lock);
> ret = sunrise_read_word(sunrise, SUNRISE_CHIP_TEMPERATURE_REG,
> &value);
> - *val = value;
> mutex_unlock(&sunrise->lock);
>
> if (ret)
> return ret;
>
> + *val = value;
> return IIO_VAL_INT;
>
> default:
prev parent reply other threads:[~2021-12-28 18:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-24 15:08 [PATCH] iio: chemical: set val parameter only on success trix
2021-12-28 18:39 ` 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=20211228183925.059884e1@jic23-huawei \
--to=jic23@kernel.org \
--cc=jacopo@jmondi.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=trix@redhat.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