linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Brian Masney <masneyb@onstation.org>
Cc: linux-iio@vger.kernel.org, gregkh@linuxfoundation.org,
	devel@driverdev.osuosl.org, knaack.h@gmx.de, lars@metafoo.de,
	pmeerw@pmeerw.net, linux-kernel@vger.kernel.org,
	Jon.Brenner@ams.com
Subject: Re: [PATCH 08/12] staging: iio: tsl2x7x: add error handling to tsl2x7x_prox_cal()
Date: Sat, 10 Mar 2018 14:44:34 +0000	[thread overview]
Message-ID: <20180310144434.1cd58941@archlinux> (raw)
In-Reply-To: <20180304014942.18727-9-masneyb@onstation.org>

On Sat,  3 Mar 2018 20:49:38 -0500
Brian Masney <masneyb@onstation.org> wrote:

> 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: Brian Masney <masneyb@onstation.org>
applied.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 36 ++++++++++++++++++++++++++----------
>  1 file changed, 26 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index 380a6c96a69a..8adc6db44790 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -807,10 +807,10 @@ static void tsl2x7x_prox_calculate(int *data, int length,
>   * Calculates a standard deviation based on the samples,
>   * 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 i;
> +	int i, ret;
>  	struct tsl2x7x_prox_stat prox_stat_data[2];
>  	struct tsl2x7x_prox_stat *cal;
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> @@ -825,25 +825,33 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
>  	}
>  
>  	/* 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*/
>  	tmp_irq_settings = chip->settings.interrupts_en;
>  	chip->settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL;
>  
>  	/*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*/
>  	for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
>  		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;
>  		dev_info(&chip->client->dev, "2 i=%d prox data= %d\n",
>  			 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];
>  	tsl2x7x_prox_calculate(prox_history,
>  			       chip->settings.prox_max_samples_cal, cal);
> @@ -857,8 +865,13 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
>  
>  	/* back to the way they were */
>  	chip->settings.interrupts_en = tmp_irq_settings;
> -	if (current_state == TSL2X7X_CHIP_WORKING)
> -		tsl2x7x_chip_on(indio_dev);
> +	if (current_state == TSL2X7X_CHIP_WORKING) {
> +		ret = tsl2x7x_chip_on(indio_dev);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
> +	return 0;
>  }
>  
>  static ssize_t
> @@ -1018,8 +1031,11 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
>  	if (strtobool(buf, &value))
>  		return -EINVAL;
>  
> -	if (value)
> -		tsl2x7x_prox_cal(indio_dev);
> +	if (value) {
> +		ret = tsl2x7x_prox_cal(indio_dev);
> +		if (ret < 0)
> +			return ret;
> +	}
>  
>  	ret = tsl2x7x_invoke_change(indio_dev);
>  	if (ret < 0)


  reply	other threads:[~2018-03-10 14:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-04  1:49 [PATCH 00/12] staging cleanups Brian Masney
2018-03-04  1:49 ` [PATCH 01/12] staging: iio: tsl2x7x: remove power functions from tsl2X7X_platform_data Brian Masney
2018-03-10 14:20   ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 02/12] staging: iio: tsl2x7x: add common function for clearing interrupts Brian Masney
2018-03-10 14:27   ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 03/12] staging: iio: tsl2x7x: add common function for reading chip status Brian Masney
2018-03-10 14:34   ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 04/12] staging: iio: tsl2x7x: add common function for writing to the control register Brian Masney
2018-03-10 14:36   ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 05/12] staging: iio: tsl2x7x: convert mutex_trylock() to mutex_lock() Brian Masney
2018-03-10 14:39   ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 06/12] staging: iio: tsl2x7x: correctly return errors in tsl2x7x_get_prox() Brian Masney
2018-03-10 14:42   ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 07/12] staging: iio: tsl2x7x: correct 'Avoid CamelCase' warning from checkpatch Brian Masney
2018-03-10 14:43   ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 08/12] staging: iio: tsl2x7x: add error handling to tsl2x7x_prox_cal() Brian Masney
2018-03-10 14:44   ` Jonathan Cameron [this message]
2018-03-04  1:49 ` [PATCH 09/12] staging: iio: tsl2x7x: add missing error checks Brian Masney
2018-03-10 14:45   ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 10/12] staging: iio: tsl2x7x: make logging consistent and correct newlines Brian Masney
2018-03-10 14:52   ` Jonathan Cameron
2018-03-11 13:45     ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 11/12] staging: iio: tsl2x7x: remove unnecessary sysfs attribute Brian Masney
2018-03-10 14:54   ` Jonathan Cameron
2018-03-04  1:49 ` [PATCH 12/12] staging: iio: tsl2x7x: make proximity sensor function correctly Brian Masney
2018-03-10 14:56   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180310144434.1cd58941@archlinux \
    --to=jic23@kernel.org \
    --cc=Jon.Brenner@ams.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masneyb@onstation.org \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).