iio: imu: adis16480: assign bias value only if operation succeeded
authorAlexandru Ardelean <alexandru.ardelean@analog.com>
Fri, 1 Nov 2019 09:35:03 +0000 (11:35 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Jan 2020 07:19:35 +0000 (08:19 +0100)
commit 9b742763d9d4195e823ae6ece760c9ed0500c1dc upstream.

This was found only after the whole thing with the inline functions, but
the compiler actually found something. The value of the `bias` (in
adis16480_get_calibbias()) should only be set if the read operation was
successful.

No actual known problem occurs as users of this function all
ultimately check the return value.  Hence probably not stable material.

Fixes: 2f3abe6cbb6c9 ("iio:imu: Add support for the ADIS16480 and similar IMUs")
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/imu/adis16480.c

index c950aa10d0ae0ec9b6a1e2ef43eec256b98c9696..5abe095901c83dbb0c98b045c44c49fabd1867f0 100644 (file)
@@ -372,12 +372,14 @@ static int adis16480_get_calibbias(struct iio_dev *indio_dev,
        case IIO_MAGN:
        case IIO_PRESSURE:
                ret = adis_read_reg_16(&st->adis, reg, &val16);
-               *bias = sign_extend32(val16, 15);
+               if (ret == 0)
+                       *bias = sign_extend32(val16, 15);
                break;
        case IIO_ANGL_VEL:
        case IIO_ACCEL:
                ret = adis_read_reg_32(&st->adis, reg, &val32);
-               *bias = sign_extend32(val32, 31);
+               if (ret == 0)
+                       *bias = sign_extend32(val32, 31);
                break;
        default:
                        ret = -EINVAL;