staging: iio: tsl2x7x: correctly return errors in tsl2x7x_get_prox()
authorBrian Masney <masneyb@onstation.org>
Sun, 4 Mar 2018 01:49:36 +0000 (20:49 -0500)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 10 Mar 2018 14:41:47 +0000 (14:41 +0000)
Not all errors that occurred in tsl2x7x_get_prox() were correctly
reported in the return value. This patch changes the error handling
so that errors are now returned properly.

Note that the ret variable is from the call to tsl2x7x_read_status(),
and it already has the correct error check. The -EINVAL error code is
for an unexpected value in the register.

This patch also corrects an unnecessary word wrap in the call to
le16_to_cpup() while changes are being made to this code.

Signed-off-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/staging/iio/light/tsl2x7x.c

index 5c611250127f9c4779453114c8923945fe586936..cc209b64ed5a952ec907dd9114c881fc4b9458b0 100644 (file)
@@ -489,16 +489,20 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
        case tmd2671:
        case tsl2771:
        case tmd2771:
-               if (!(ret & TSL2X7X_STA_ADC_VALID))
+               if (!(ret & TSL2X7X_STA_ADC_VALID)) {
+                       ret = -EINVAL;
                        goto prox_poll_err;
+               }
                break;
        case tsl2572:
        case tsl2672:
        case tmd2672:
        case tsl2772:
        case tmd2772:
-               if (!(ret & TSL2X7X_STA_PRX_VALID))
+               if (!(ret & TSL2X7X_STA_PRX_VALID)) {
+                       ret = -EINVAL;
                        goto prox_poll_err;
+               }
                break;
        }
 
@@ -512,14 +516,13 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
                chdata[i] = ret;
        }
 
-       chip->prox_data =
-                       le16_to_cpup((const __le16 *)&chdata[0]);
+       chip->prox_data = le16_to_cpup((const __le16 *)&chdata[0]);
+       ret = chip->prox_data;
 
 prox_poll_err:
-
        mutex_unlock(&chip->prox_mutex);
 
-       return chip->prox_data;
+       return ret;
 }
 
 /**