Skip to content

Commit ab87117

Browse files
Tom Rixgregkh
authored andcommitted
iio: chemical: sunrise_co2: set val parameter only on success
[ Upstream commit 38ac2f0 ] 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: c397894 ("iio: chemical: Add Senseair Sunrise 006-0-007 driver") Signed-off-by: Tom Rix <trix@redhat.com> Link: https://lore.kernel.org/r/20211224150833.3278236-1-trix@redhat.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 41bd136 commit ab87117

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/iio/chemical/sunrise_co2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,24 +407,24 @@ static int sunrise_read_raw(struct iio_dev *iio_dev,
407407
mutex_lock(&sunrise->lock);
408408
ret = sunrise_read_word(sunrise, SUNRISE_CO2_FILTERED_COMP_REG,
409409
&value);
410-
*val = value;
411410
mutex_unlock(&sunrise->lock);
412411

413412
if (ret)
414413
return ret;
415414

415+
*val = value;
416416
return IIO_VAL_INT;
417417

418418
case IIO_TEMP:
419419
mutex_lock(&sunrise->lock);
420420
ret = sunrise_read_word(sunrise, SUNRISE_CHIP_TEMPERATURE_REG,
421421
&value);
422-
*val = value;
423422
mutex_unlock(&sunrise->lock);
424423

425424
if (ret)
426425
return ret;
427426

427+
*val = value;
428428
return IIO_VAL_INT;
429429

430430
default:

0 commit comments

Comments
 (0)