Skip to content

Commit 288320f

Browse files
Colin Ian Kingjic23
authored andcommitted
iio: tsl2x7x/tsl2772: avoid potential division by zero
It may be possible for tsl2772_get_lux to return a zero lux value and hence a division by zero can occur when lux_val is zero. Check for this case and return -ERANGE to avoid the division by zero. Detected by CoverityScan, CID#1469484 ("Division or modulo by zero") Signed-off-by: Colin Ian King <[email protected]> Acked-by: Brian Masney <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 13399ff commit 288320f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/iio/light/tsl2772.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
582582
"%s: failed to get lux\n", __func__);
583583
return lux_val;
584584
}
585+
if (lux_val == 0)
586+
return -ERANGE;
585587

586588
ret = (chip->settings.als_cal_target * chip->settings.als_gain_trim) /
587589
lux_val;

0 commit comments

Comments
 (0)