Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: light: apds9306: Fix input arguments to in_range()

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>
Link: https://lore.kernel.org/r/20240427090914.37274-1-subhajit.ghosh@tweaklogic.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Subhajit Ghosh and committed by
Jonathan Cameron
0d8d6264 84e79a7f

+6 -6
+6 -6
drivers/iio/light/apds9306.c
··· 55 55 #define APDS9306_ALS_DATA_STAT_MASK BIT(3) 56 56 57 57 #define APDS9306_ALS_THRES_VAL_MAX (BIT(20) - 1) 58 - #define APDS9306_ALS_THRES_VAR_VAL_MAX (BIT(3) - 1) 59 - #define APDS9306_ALS_PERSIST_VAL_MAX (BIT(4) - 1) 58 + #define APDS9306_ALS_THRES_VAR_NUM_VALS 8 59 + #define APDS9306_ALS_PERSIST_NUM_VALS 16 60 60 #define APDS9306_ALS_READ_DATA_DELAY_US (20 * USEC_PER_MSEC) 61 61 #define APDS9306_NUM_REPEAT_RATES 7 62 62 #define APDS9306_INT_SRC_CLEAR 0 ··· 726 726 if (ret) 727 727 return ret; 728 728 729 - if (!in_range(period, 0, APDS9306_ALS_PERSIST_VAL_MAX)) 729 + if (!in_range(period, 0, APDS9306_ALS_PERSIST_NUM_VALS)) 730 730 return -EINVAL; 731 731 732 732 *val = period; ··· 738 738 { 739 739 struct apds9306_regfields *rf = &data->rf; 740 740 741 - if (!in_range(val, 0, APDS9306_ALS_PERSIST_VAL_MAX)) 741 + if (!in_range(val, 0, APDS9306_ALS_PERSIST_NUM_VALS)) 742 742 return -EINVAL; 743 743 744 744 return regmap_field_write(rf->int_persist_val, val); ··· 796 796 if (ret) 797 797 return ret; 798 798 799 - if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_VAL_MAX)) 799 + if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_NUM_VALS)) 800 800 return -EINVAL; 801 801 802 802 *val = thr_adpt; ··· 808 808 { 809 809 struct apds9306_regfields *rf = &data->rf; 810 810 811 - if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_VAL_MAX)) 811 + if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_NUM_VALS)) 812 812 return -EINVAL; 813 813 814 814 return regmap_field_write(rf->int_thresh_var_val, val);