* [PATCH][next] iio: tsl2x7x/tsl2772: avoid potential division by zero
@ 2018-05-30 18:19 Colin King
2018-05-31 9:28 ` Brian Masney
0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2018-05-30 18:19 UTC (permalink / raw)
To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Brian Masney, linux-iio
Cc: kernel-janitors, linux-kernel
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] iio: tsl2x7x/tsl2772: avoid potential division by zero
2018-05-30 18:19 [PATCH][next] iio: tsl2x7x/tsl2772: avoid potential division by zero Colin King
@ 2018-05-31 9:28 ` Brian Masney
2018-06-03 15:12 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Brian Masney @ 2018-05-31 9:28 UTC (permalink / raw)
To: Colin King
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, linux-iio, kernel-janitors, linux-kernel
On Wed, May 30, 2018 at 07:19:36PM +0100, Colin King wrote:
> 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>
Acked-by: Brian Masney <masneyb@onstation.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] iio: tsl2x7x/tsl2772: avoid potential division by zero
2018-05-31 9:28 ` Brian Masney
@ 2018-06-03 15:12 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2018-06-03 15:12 UTC (permalink / raw)
To: Brian Masney
Cc: Colin King, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, linux-iio, kernel-janitors, linux-kernel
On Thu, 31 May 2018 05:28:01 -0400
Brian Masney <masneyb@onstation.org> wrote:
> On Wed, May 30, 2018 at 07:19:36PM +0100, Colin King wrote:
> > 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>
>
> Acked-by: Brian Masney <masneyb@onstation.org>
Applied to the fixes-togreg branch of iio.git.
As there was nothing in that branch that is going upstream until after
the merge window closes, I moved it forward to match staging/staging-next.
Jonathan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-03 15:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-30 18:19 [PATCH][next] iio: tsl2x7x/tsl2772: avoid potential division by zero Colin King
2018-05-31 9:28 ` Brian Masney
2018-06-03 15:12 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).