iio: accel: bma220: Fix returned codes from bma220_init(), bma220_deinit()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 31 Aug 2020 09:08:06 +0000 (12:08 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 3 Sep 2020 18:40:58 +0000 (19:40 +0100)
Potentially bma220_init() and bma220_deinit() may return positive codes.
Fix the logic to return proper error codes instead.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20200831090813.78841-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/bma220_spi.c

index da8b36cc8628968d0b7c5d1eff55e03cd6aaee10..3247b9c8abcb9e694de58e32b54504d058533ed3 100644 (file)
@@ -198,10 +198,12 @@ static int bma220_init(struct spi_device *spi)
 
        /* Make sure the chip is powered on */
        ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
+       if (ret == BMA220_SUSPEND_WAKE)
+               ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
        if (ret < 0)
                return ret;
-       else if (ret == BMA220_SUSPEND_WAKE)
-               return bma220_read_reg(spi, BMA220_REG_SUSPEND);
+       if (ret == BMA220_SUSPEND_WAKE)
+               return -EBUSY;
 
        return 0;
 }
@@ -212,10 +214,12 @@ static int bma220_deinit(struct spi_device *spi)
 
        /* Make sure the chip is powered off */
        ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
+       if (ret == BMA220_SUSPEND_SLEEP)
+               ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
        if (ret < 0)
                return ret;
-       else if (ret == BMA220_SUSPEND_SLEEP)
-               return bma220_read_reg(spi, BMA220_REG_SUSPEND);
+       if (ret == BMA220_SUSPEND_SLEEP)
+               return -EBUSY;
 
        return 0;
 }
@@ -245,7 +249,7 @@ static int bma220_probe(struct spi_device *spi)
        indio_dev->available_scan_masks = bma220_accel_scan_masks;
 
        ret = bma220_init(data->spi_device);
-       if (ret < 0)
+       if (ret)
                return ret;
 
        ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time,