mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Rix <trix@redhat.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: roan@protonic.nl, 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: scd4x: check return of scd4x_write_and_fetch
Date: Mon, 28 Feb 2022 13:06:32 -0800	[thread overview]
Message-ID: <b13706f7-4a9e-ba3d-2828-8570c409096c@redhat.com> (raw)
In-Reply-To: <20220227174850.73520e39@jic23-huawei>


On 2/27/22 9:48 AM, Jonathan Cameron wrote:
> On Sun, 27 Feb 2022 07:43:31 -0800
> trix@redhat.com wrote:
>
>> From: Tom Rix <trix@redhat.com>
>>
>> Clang static analysis reports this problem
>> scd4x.c:474:10: warning: The left operand of '==' is a
>>    garbage value
>>    if (val == 0xff) {
>>        ~~~ ^
>> val is only set from a successful call to scd4x_write_and_fetch()
>> So check it's return.
>>
>> Fixes: 49d22b695cbb ("drivers: iio: chemical: Add support for Sensirion SCD4x CO2 sensor")
>> Signed-off-by: Tom Rix <trix@redhat.com>
> Good find, but I'd prefer a separate check on ret inline with what the
> other error checking paths in that function are doing.
>
>> ---
>>   drivers/iio/chemical/scd4x.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/chemical/scd4x.c b/drivers/iio/chemical/scd4x.c
>> index 20d4e7584e923..b978330fb761c 100644
>> --- a/drivers/iio/chemical/scd4x.c
>> +++ b/drivers/iio/chemical/scd4x.c
>> @@ -471,7 +471,7 @@ static ssize_t calibration_forced_value_store(struct device *dev,
>>   	ret = scd4x_write_and_fetch(state, CMD_FRC, arg, &val, sizeof(val));
>>   	mutex_unlock(&state->lock);
>>   
>> -	if (val == 0xff) {
>> +	if (!ret && val == 0xff) {
>>   		dev_err(dev, "forced calibration has failed");
>>   		return -EINVAL;
>>   	}
> Prefer
>
> 	if (ret)
> 		return ret;
>
> 	if (val == 0xff) {
> 		dev_err(dev, "...
> 		return -EINVAL;
> 	}

ok and the next line can be simplified to

return len;

Tom

> Thanks,
>
> Jonathan
>


      reply	other threads:[~2022-02-28 21:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-27 15:43 trix
2022-02-27 17:48 ` Jonathan Cameron
2022-02-28 21:06   ` Tom Rix [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=b13706f7-4a9e-ba3d-2828-8570c409096c@redhat.com \
    --to=trix@redhat.com \
    --cc=jic23@kernel.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=roan@protonic.nl \
    /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

all inboxes | Powered by JetHome®