staging: iio: tsl2583: check if chip is in a working state in in_illuminance_calibrat...
authorBrian Masney <masneyb@onstation.org>
Sat, 12 Nov 2016 18:19:16 +0000 (13:19 -0500)
committerJonathan Cameron <jic23@kernel.org>
Sun, 13 Nov 2016 13:07:17 +0000 (13:07 +0000)
in_illuminance_calibrate_store() did not check to see if the chip is
in a working state. This patch adds the proper check. The return value
from taos_als_calibrate() was also not checked in this function, so the
proper check was also added while changes are being made here.

Signed-off-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/staging/iio/light/tsl2583.c

index 1a7be120ba256d7c43d21986cb8756337ac38bc5..de54e74296726326a9c22b43a2ff957c42c6af12 100644 (file)
@@ -501,16 +501,27 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct tsl2583_chip *chip = iio_priv(indio_dev);
-       int value;
+       int value, ret;
 
        if (kstrtoint(buf, 0, &value) || value != 1)
                return -EINVAL;
 
        mutex_lock(&chip->als_mutex);
-       taos_als_calibrate(indio_dev);
+
+       if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
+               ret = -EBUSY;
+               goto done;
+       }
+
+       ret = taos_als_calibrate(indio_dev);
+       if (ret < 0)
+               goto done;
+
+       ret = len;
+done:
        mutex_unlock(&chip->als_mutex);
 
-       return len;
+       return ret;
 }
 
 static ssize_t in_illuminance_lux_table_show(struct device *dev,