Skip to content

Commit

Permalink
iio: scd4x: check return of scd4x_write_and_fetch
Browse files Browse the repository at this point in the history
commit f502321 upstream.

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: 49d22b6 ("drivers: iio: chemical: Add support for Sensirion SCD4x CO2 sensor")
Signed-off-by: Tom Rix <trix@redhat.com>
Link: https://lore.kernel.org/r/20220301025223.223223-1-trix@redhat.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
trixirt authored and gregkh committed May 9, 2022
1 parent 7462f0c commit 3ea6c6c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/iio/chemical/scd4x.c
Expand Up @@ -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);
Expand Down

0 comments on commit 3ea6c6c

Please sign in to comment.