lkml.org 
[lkml]   [2018]   [May]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH][next] iio: tsl2x7x/tsl2772: avoid potential division by zero
Date
From: Colin Ian King <colin.king@canonical.com>

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 <colin.king@canonical.com>
---
drivers/iio/light/tsl2772.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
index 34d42a2504c9..df5b2a0da96c 100644
--- a/drivers/iio/light/tsl2772.c
+++ b/drivers/iio/light/tsl2772.c
@@ -582,6 +582,8 @@ static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
"%s: failed to get lux\n", __func__);
return lux_val;
}
+ if (lux_val == 0)
+ return -ERANGE;

ret = (chip->settings.als_cal_target * chip->settings.als_gain_trim) /
lux_val;
--
2.17.0
\
 
 \ /
  Last update: 2018-05-30 20:20    [W:0.034 / U:0.500 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site