LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Brian Masney <masneyb@onstation.org>
Cc: devel@driverdev.osuosl.org, lars@metafoo.de,
	linux-iio@vger.kernel.org, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, pmeerw@pmeerw.net, knaack.h@gmx.de,
	drew.paterson@ams.com
Subject: Re: [PATCH v3 7/9] staging: iio: tsl2x7x: add range checking to tsl2x7x_write_raw
Date: Sat, 12 May 2018 12:23:34 +0100	[thread overview]
Message-ID: <20180512122334.79c1bd66@archlinux> (raw)
In-Reply-To: <20180511001223.12378-8-masneyb@onstation.org>

On Thu, 10 May 2018 20:12:21 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The CALIBBIAS and INT_TIME masks in tsl2x7x_write_raw did not have any
> range checking in place so this patch adds the appropriate range
> checking. The defines TSL2X7X_ALS_GAIN_TRIM_{MIN,MAX} are also
> introduced by this patch.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index 0218eabcd6d7..f9500afab30c 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -103,6 +103,9 @@
>  #define TSL2X7X_CNTL_PROXPON_ENBL	0x0F
>  #define TSL2X7X_CNTL_INTPROXPON_ENBL	0x2F
>  
> +#define TSL2X7X_ALS_GAIN_TRIM_MIN	250
> +#define TSL2X7X_ALS_GAIN_TRIM_MAX	4000
> +
>  /* TAOS txx2x7x Device family members */
>  enum {
>  	tsl2571,
> @@ -581,7 +584,7 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
>  
>  	ret = (chip->settings.als_cal_target * chip->settings.als_gain_trim) /
>  			lux_val;
> -	if (ret < 250 || ret > 4000)
> +	if (ret < TSL2X7X_ALS_GAIN_TRIM_MIN || ret > TSL2X7X_ALS_GAIN_TRIM_MAX)
>  		return -ERANGE;
>  
>  	chip->settings.als_gain_trim = ret;
> @@ -1209,9 +1212,17 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  		}
>  		break;
>  	case IIO_CHAN_INFO_CALIBBIAS:
> +		if (val < TSL2X7X_ALS_GAIN_TRIM_MIN ||
> +		    val > TSL2X7X_ALS_GAIN_TRIM_MAX)
> +			return -EINVAL;
> +
>  		chip->settings.als_gain_trim = val;
>  		break;
>  	case IIO_CHAN_INFO_INT_TIME:
> +		if (val != 0 || val2 < tsl2x7x_int_time_avail[chip->id][1] ||
> +		    val2 > tsl2x7x_int_time_avail[chip->id][5])
> +			return -EINVAL;
> +
>  		chip->settings.als_time = 256 -
>  			(val2 / tsl2x7x_int_time_avail[chip->id][3]);
>  		break;

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2018-05-12 11:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-11  0:12 [PATCH v3 0/9] staging: iio: tsl2x7x: move out of staging Brian Masney
2018-05-11  0:12 ` [PATCH v3 1/9] staging: iio: tsl2x7x: remove unnecessary whitespace Brian Masney
2018-05-12 11:15   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 2/9] staging: iio: tsl2x7x: use direct returns Brian Masney
2018-05-12 11:16   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 3/9] staging: iio: tsl2x7x: turn chip off if IIO device registration fails Brian Masney
2018-05-12 11:16   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 4/9] staging: iio: tsl2x7x: use macro to populate tsl2X7X_device_info Brian Masney
2018-05-12 11:20   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 5/9] staging: iio: tsl2x7x: convert to use read_avail Brian Masney
2018-05-12 11:20   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 6/9] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values Brian Masney
2018-05-12 11:21   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 7/9] staging: iio: tsl2x7x: add range checking to tsl2x7x_write_raw Brian Masney
2018-05-12 11:23   ` Jonathan Cameron [this message]
2018-05-11  0:12 ` [PATCH v3 8/9] staging: iio: tsl2x7x: rename driver to tsl2772 Brian Masney
2018-05-12 11:25   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 9/9] staging: iio: tsl2x7x/tsl2772: move out of staging Brian Masney
2018-05-11  0:32   ` Brian Masney
2018-05-12 11:44     ` Jonathan Cameron
2018-05-12 12:36       ` Brian Masney
2018-05-12 17:44         ` 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=20180512122334.79c1bd66@archlinux \
    --to=jic23@kernel.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=drew.paterson@ams.com \
    --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 \
    --subject='Re: [PATCH v3 7/9] staging: iio: tsl2x7x: add range checking to tsl2x7x_write_raw' \
    /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

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).