linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: light: apds9306: Fix input arguments to in_range()
@ 2024-04-27  9:09 Subhajit Ghosh
  2024-04-28 11:47 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Subhajit Ghosh @ 2024-04-27  9:09 UTC (permalink / raw)
  To: Jonathan Cameron, Lars-Peter Clausen, Dan Carpenter
  Cc: Subhajit Ghosh, linux-iio, linux-kernel

Third input argument to in_range() function requires the number of
values in range, not the last value in that range. Update macro for
persistence and adaptive threshold to reflect number of values
supported instead of the maximum values supported.

Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
Signed-off-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
---
 drivers/iio/light/apds9306.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
index 46c647ccd44c..d6627b3e6000 100644
--- a/drivers/iio/light/apds9306.c
+++ b/drivers/iio/light/apds9306.c
@@ -55,8 +55,8 @@
 #define APDS9306_ALS_DATA_STAT_MASK	BIT(3)
 
 #define APDS9306_ALS_THRES_VAL_MAX	(BIT(20) - 1)
-#define APDS9306_ALS_THRES_VAR_VAL_MAX	(BIT(3) - 1)
-#define APDS9306_ALS_PERSIST_VAL_MAX	(BIT(4) - 1)
+#define APDS9306_ALS_THRES_VAR_NUM_VALS	8
+#define APDS9306_ALS_PERSIST_NUM_VALS	16
 #define APDS9306_ALS_READ_DATA_DELAY_US	(20 * USEC_PER_MSEC)
 #define APDS9306_NUM_REPEAT_RATES	7
 #define APDS9306_INT_SRC_CLEAR	0
@@ -726,7 +726,7 @@ static int apds9306_event_period_get(struct apds9306_data *data, int *val)
 	if (ret)
 		return ret;
 
-	if (!in_range(period, 0, APDS9306_ALS_PERSIST_VAL_MAX))
+	if (!in_range(period, 0, APDS9306_ALS_PERSIST_NUM_VALS))
 		return -EINVAL;
 
 	*val = period;
@@ -738,7 +738,7 @@ static int apds9306_event_period_set(struct apds9306_data *data, int val)
 {
 	struct apds9306_regfields *rf = &data->rf;
 
-	if (!in_range(val, 0, APDS9306_ALS_PERSIST_VAL_MAX))
+	if (!in_range(val, 0, APDS9306_ALS_PERSIST_NUM_VALS))
 		return -EINVAL;
 
 	return regmap_field_write(rf->int_persist_val, val);
@@ -796,7 +796,7 @@ static int apds9306_event_thresh_adaptive_get(struct apds9306_data *data, int *v
 	if (ret)
 		return ret;
 
-	if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_VAL_MAX))
+	if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_NUM_VALS))
 		return -EINVAL;
 
 	*val = thr_adpt;
@@ -808,7 +808,7 @@ static int apds9306_event_thresh_adaptive_set(struct apds9306_data *data, int va
 {
 	struct apds9306_regfields *rf = &data->rf;
 
-	if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_VAL_MAX))
+	if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_NUM_VALS))
 		return -EINVAL;
 
 	return regmap_field_write(rf->int_thresh_var_val, val);

base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: light: apds9306: Fix input arguments to in_range()
  2024-04-27  9:09 [PATCH] iio: light: apds9306: Fix input arguments to in_range() Subhajit Ghosh
@ 2024-04-28 11:47 ` Jonathan Cameron
  2024-04-28 12:06   ` Subhajit Ghosh
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2024-04-28 11:47 UTC (permalink / raw)
  To: Subhajit Ghosh; +Cc: Lars-Peter Clausen, Dan Carpenter, linux-iio, linux-kernel

On Sat, 27 Apr 2024 18:39:14 +0930
Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote:

> Third input argument to in_range() function requires the number of
> values in range, not the last value in that range. Update macro for
> persistence and adaptive threshold to reflect number of values
> supported instead of the maximum values supported.
> 
> Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
> Signed-off-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
Applied to the togreg branch of iio.git. Pushed out initially as testing
for 0-day to take a first look.

Thanks,

Jonathan

> ---
>  drivers/iio/light/apds9306.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
> index 46c647ccd44c..d6627b3e6000 100644
> --- a/drivers/iio/light/apds9306.c
> +++ b/drivers/iio/light/apds9306.c
> @@ -55,8 +55,8 @@
>  #define APDS9306_ALS_DATA_STAT_MASK	BIT(3)
>  
>  #define APDS9306_ALS_THRES_VAL_MAX	(BIT(20) - 1)
> -#define APDS9306_ALS_THRES_VAR_VAL_MAX	(BIT(3) - 1)
> -#define APDS9306_ALS_PERSIST_VAL_MAX	(BIT(4) - 1)
> +#define APDS9306_ALS_THRES_VAR_NUM_VALS	8
> +#define APDS9306_ALS_PERSIST_NUM_VALS	16
>  #define APDS9306_ALS_READ_DATA_DELAY_US	(20 * USEC_PER_MSEC)
>  #define APDS9306_NUM_REPEAT_RATES	7
>  #define APDS9306_INT_SRC_CLEAR	0
> @@ -726,7 +726,7 @@ static int apds9306_event_period_get(struct apds9306_data *data, int *val)
>  	if (ret)
>  		return ret;
>  
> -	if (!in_range(period, 0, APDS9306_ALS_PERSIST_VAL_MAX))
> +	if (!in_range(period, 0, APDS9306_ALS_PERSIST_NUM_VALS))
>  		return -EINVAL;
>  
>  	*val = period;
> @@ -738,7 +738,7 @@ static int apds9306_event_period_set(struct apds9306_data *data, int val)
>  {
>  	struct apds9306_regfields *rf = &data->rf;
>  
> -	if (!in_range(val, 0, APDS9306_ALS_PERSIST_VAL_MAX))
> +	if (!in_range(val, 0, APDS9306_ALS_PERSIST_NUM_VALS))
>  		return -EINVAL;
>  
>  	return regmap_field_write(rf->int_persist_val, val);
> @@ -796,7 +796,7 @@ static int apds9306_event_thresh_adaptive_get(struct apds9306_data *data, int *v
>  	if (ret)
>  		return ret;
>  
> -	if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_VAL_MAX))
> +	if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_NUM_VALS))
>  		return -EINVAL;
>  
>  	*val = thr_adpt;
> @@ -808,7 +808,7 @@ static int apds9306_event_thresh_adaptive_set(struct apds9306_data *data, int va
>  {
>  	struct apds9306_regfields *rf = &data->rf;
>  
> -	if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_VAL_MAX))
> +	if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_NUM_VALS))
>  		return -EINVAL;
>  
>  	return regmap_field_write(rf->int_thresh_var_val, val);
> 
> base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: light: apds9306: Fix input arguments to in_range()
  2024-04-28 11:47 ` Jonathan Cameron
@ 2024-04-28 12:06   ` Subhajit Ghosh
  0 siblings, 0 replies; 3+ messages in thread
From: Subhajit Ghosh @ 2024-04-28 12:06 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Dan Carpenter, linux-iio, linux-kernel

On 28/4/24 21:17, Jonathan Cameron wrote:
> On Sat, 27 Apr 2024 18:39:14 +0930
> Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote:
> 
>> Third input argument to in_range() function requires the number of
>> values in range, not the last value in that range. Update macro for
>> persistence and adaptive threshold to reflect number of values
>> supported instead of the maximum values supported.
>>
>> Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
>> Signed-off-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
> Applied to the togreg branch of iio.git. Pushed out initially as testing
> for 0-day to take a first look.
> 
> Thanks,
> 
> Jonathan
> 
Thank you Jonathan.

Regards,
Subhajit Ghosh


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-28 12:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-27  9:09 [PATCH] iio: light: apds9306: Fix input arguments to in_range() Subhajit Ghosh
2024-04-28 11:47 ` Jonathan Cameron
2024-04-28 12:06   ` Subhajit Ghosh

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