lkml.org 
[lkml]   [2022]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.16 0510/1039] iio: chemical: sunrise_co2: set val parameter only on success
    Date
    From: Tom Rix <trix@redhat.com>

    [ Upstream commit 38ac2f038666521f94d4fa37b5a9441cef832ccf ]

    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>
    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>
    ---
    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:
    --
    2.34.1


    \
     
     \ /
      Last update: 2022-01-25 01:13    [W:4.374 / U:1.252 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site