Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2] iio: scd4x: check return of scd4x_write_and_fetch
@ 2022-03-01  2:52 trix
  2022-03-20 15:39 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2022-03-01  2:52 UTC (permalink / raw)
  To: roan, jic23, lars, nathan, ndesaulniers
  Cc: linux-iio, linux-kernel, llvm, Tom Rix

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>
---
v2: rework return on error logic to be similar to existing code

 drivers/iio/chemical/scd4x.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/chemical/scd4x.c b/drivers/iio/chemical/scd4x.c
index 20d4e7584e923..37143b5526ee6 100644
--- a/drivers/iio/chemical/scd4x.c
+++ b/drivers/iio/chemical/scd4x.c
@@ -471,12 +471,15 @@ 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 (ret)
+		return ret;
+
 	if (val == 0xff) {
 		dev_err(dev, "forced calibration has failed");
 		return -EINVAL;
 	}
 
-	return ret ?: len;
+	return len;
 }
 
 static IIO_DEVICE_ATTR_RW(calibration_auto_enable, 0);
-- 
2.26.3


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

* Re: [PATCH v2] iio: scd4x: check return of scd4x_write_and_fetch
  2022-03-01  2:52 [PATCH v2] iio: scd4x: check return of scd4x_write_and_fetch trix
@ 2022-03-20 15:39 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2022-03-20 15:39 UTC (permalink / raw)
  To: trix; +Cc: roan, lars, nathan, ndesaulniers, linux-iio, linux-kernel, llvm

On Mon, 28 Feb 2022 18:52:23 -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>

Hi Tom,

This looks good to me.  Timing was a bit unfortunate so now I'll queue this up for post
rc1.  Hence applied to my local copy of fixes-togreg (which includes the stuff that
should go in during the merge window) but not pushed out until I can rebase on rc1.

Thanks,

Jonathan

> ---
> v2: rework return on error logic to be similar to existing code
> 
>  drivers/iio/chemical/scd4x.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/chemical/scd4x.c b/drivers/iio/chemical/scd4x.c
> index 20d4e7584e923..37143b5526ee6 100644
> --- a/drivers/iio/chemical/scd4x.c
> +++ b/drivers/iio/chemical/scd4x.c
> @@ -471,12 +471,15 @@ 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 (ret)
> +		return ret;
> +
>  	if (val == 0xff) {
>  		dev_err(dev, "forced calibration has failed");
>  		return -EINVAL;
>  	}
>  
> -	return ret ?: len;
> +	return len;
>  }
>  
>  static IIO_DEVICE_ATTR_RW(calibration_auto_enable, 0);


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

end of thread, other threads:[~2022-03-20 15:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-01  2:52 [PATCH v2] iio: scd4x: check return of scd4x_write_and_fetch trix
2022-03-20 15:39 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox