]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: light: apds9306: Fix off by one in apds9306_sampling_freq_get()
authorDan Carpenter <dan.carpenter@linaro.org>
Thu, 4 Apr 2024 07:31:25 +0000 (10:31 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 6 Apr 2024 15:41:27 +0000 (16:41 +0100)
The > comparison needs to be >= to prevent an out of bounds access.

Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
Link: https://lore.kernel.org/r/69c5cb83-0209-40ff-a276-a0ae5e81c528@moroto.mountain
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/light/apds9306.c

index 4d8490602cd7ce96f0847e56b7b4803674ac40c1..49fa6b7d5170b89c477f4744e307c34ebfe35493 100644 (file)
@@ -635,7 +635,7 @@ static int apds9306_sampling_freq_get(struct apds9306_data *data, int *val,
        if (ret)
                return ret;
 
-       if (repeat_rate_idx > ARRAY_SIZE(apds9306_repeat_rate_freq))
+       if (repeat_rate_idx >= ARRAY_SIZE(apds9306_repeat_rate_freq))
                return -EINVAL;
 
        *val = apds9306_repeat_rate_freq[repeat_rate_idx][0];