Skip to contentSkip to conversation

iio: sx9310: Off by one in sx9310_read_thresh()

PATCH Applied Dan Carpenter 4 participants 4 messages Dec 1, 2020 – Dec 13, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: sx9310: Off by one in sx9310_read_thresh()

This > should be >= to prevent reading one element beyond the end of the sx9310_pthresh_codes[] array.

Fixes ad2b473e2ba3 ("iio: sx9310: Support setting proximity thresholds")
---
 drivers/iio/proximity/sx9310.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/proximity/sx9310.c +1 -1
index a2f820997afc..62eacb22e9bc 100644
@@ -601,7 +601,7 @@ static int sx9310_read_thresh(struct sx9310_data *data,
 		return ret;
 
 	regval = FIELD_GET(SX9310_REG_PROX_CTRL8_9_PTHRESH_MASK, regval);
-	if (regval > ARRAY_SIZE(sx9310_pthresh_codes))
+	if (regval >= ARRAY_SIZE(sx9310_pthresh_codes))
 		return -EINVAL;
 
 	*val = sx9310_pthresh_codes[regval];
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 9 lines · Dan Carpenter

This > should be >= to prevent reading one element beyond the end of the sx9310_pthresh_codes[] array.

Fixes ad2b473e2ba3 ("iio: sx9310: Support setting proximity thresholds")
---
 drivers/iio/proximity/sx9310.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
maintainer Applied
#3 lore raw
In reply to Dan Carpenter
Quoted 5 lines · On Tue, 1 Dec 2020 10:03:28 +0300 Dan Carpenter <[email protected]>…

This > should be >= to prevent reading one element beyond the end of the sx9310_pthresh_codes[] array.

Fixes ad2b473e2ba3 ("iio: sx9310: Support setting proximity thresholds")

Applied to the fixes-togreg branch of iio.git which won't go anywhere now until after rc1 (and is based on the stuff queued up for the merge window)

thanks,

Jonathan

Quoted 17 lines
---
 drivers/iio/proximity/sx9310.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/proximity/sx9310.c +1 -1
index a2f820997afc..62eacb22e9bc 100644
@@ -601,7 +601,7 @@ static int sx9310_read_thresh(struct sx9310_data *data,
 		return ret;
 
 	regval = FIELD_GET(SX9310_REG_PROX_CTRL8_9_PTHRESH_MASK, regval);
-	if (regval > ARRAY_SIZE(sx9310_pthresh_codes))
+	if (regval >= ARRAY_SIZE(sx9310_pthresh_codes))
 		return -EINVAL;
 
 	*val = sx9310_pthresh_codes[regval];