Commit dbe0f59c authored by Brian Masney's avatar Brian Masney Committed by Jonathan Cameron

staging: iio: tsl2x7x: add error handling to tsl2x7x_prox_cal()

tsl2x7x_prox_cal() did not have any error checks. This patch adds
the missing error handling and ensures that any errors are reported to
user space via in_proximity0_calibrate_store().
Signed-off-by: default avatarBrian Masney <masneyb@onstation.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 6f80ff9e
...@@ -807,10 +807,10 @@ static void tsl2x7x_prox_calculate(int *data, int length, ...@@ -807,10 +807,10 @@ static void tsl2x7x_prox_calculate(int *data, int length,
* Calculates a standard deviation based on the samples, * Calculates a standard deviation based on the samples,
* and sets the threshold accordingly. * and sets the threshold accordingly.
*/ */
static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
{ {
int prox_history[MAX_SAMPLES_CAL + 1]; int prox_history[MAX_SAMPLES_CAL + 1];
int i; int i, ret;
struct tsl2x7x_prox_stat prox_stat_data[2]; struct tsl2x7x_prox_stat prox_stat_data[2];
struct tsl2x7x_prox_stat *cal; struct tsl2x7x_prox_stat *cal;
struct tsl2X7X_chip *chip = iio_priv(indio_dev); struct tsl2X7X_chip *chip = iio_priv(indio_dev);
...@@ -825,25 +825,33 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) ...@@ -825,25 +825,33 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
} }
/* have to stop to change settings */ /* have to stop to change settings */
tsl2x7x_chip_off(indio_dev); ret = tsl2x7x_chip_off(indio_dev);
if (ret < 0)
return ret;
/* Enable proximity detection save just in case prox not wanted yet*/ /* Enable proximity detection save just in case prox not wanted yet*/
tmp_irq_settings = chip->settings.interrupts_en; tmp_irq_settings = chip->settings.interrupts_en;
chip->settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL; chip->settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL;
/*turn on device if not already on*/ /*turn on device if not already on*/
tsl2x7x_chip_on(indio_dev); ret = tsl2x7x_chip_on(indio_dev);
if (ret < 0)
return ret;
/*gather the samples*/ /*gather the samples*/
for (i = 0; i < chip->settings.prox_max_samples_cal; i++) { for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
usleep_range(15000, 17500); usleep_range(15000, 17500);
tsl2x7x_get_prox(indio_dev); ret = tsl2x7x_get_prox(indio_dev);
if (ret < 0)
return ret;
prox_history[i] = chip->prox_data; prox_history[i] = chip->prox_data;
dev_info(&chip->client->dev, "2 i=%d prox data= %d\n", dev_info(&chip->client->dev, "2 i=%d prox data= %d\n",
i, chip->prox_data); i, chip->prox_data);
} }
tsl2x7x_chip_off(indio_dev); ret = tsl2x7x_chip_off(indio_dev);
if (ret < 0)
return ret;
cal = &prox_stat_data[PROX_STAT_CAL]; cal = &prox_stat_data[PROX_STAT_CAL];
tsl2x7x_prox_calculate(prox_history, tsl2x7x_prox_calculate(prox_history,
chip->settings.prox_max_samples_cal, cal); chip->settings.prox_max_samples_cal, cal);
...@@ -857,8 +865,13 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) ...@@ -857,8 +865,13 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
/* back to the way they were */ /* back to the way they were */
chip->settings.interrupts_en = tmp_irq_settings; chip->settings.interrupts_en = tmp_irq_settings;
if (current_state == TSL2X7X_CHIP_WORKING) if (current_state == TSL2X7X_CHIP_WORKING) {
tsl2x7x_chip_on(indio_dev); ret = tsl2x7x_chip_on(indio_dev);
if (ret < 0)
return ret;
}
return 0;
} }
static ssize_t static ssize_t
...@@ -1018,8 +1031,11 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev, ...@@ -1018,8 +1031,11 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
if (strtobool(buf, &value)) if (strtobool(buf, &value))
return -EINVAL; return -EINVAL;
if (value) if (value) {
tsl2x7x_prox_cal(indio_dev); ret = tsl2x7x_prox_cal(indio_dev);
if (ret < 0)
return ret;
}
ret = tsl2x7x_invoke_change(indio_dev); ret = tsl2x7x_invoke_change(indio_dev);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment