Skip to content

Commit c174b53

Browse files
Zicheng Qujic23
authored andcommitted
ad7780: fix division by zero in ad7780_write_raw()
In the ad7780_write_raw() , val2 can be zero, which might lead to a division by zero error in DIV_ROUND_CLOSEST(). The ad7780_write_raw() is based on iio_info's write_raw. While val is explicitly declared that can be zero (in read mode), val2 is not specified to be non-zero. Fixes: 9085daa ("staging: iio: ad7780: add gain & filter gpio support") Cc: [email protected] Signed-off-by: Zicheng Qu <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 3a4187e commit c174b53

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/iio/adc/ad7780.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static int ad7780_write_raw(struct iio_dev *indio_dev,
152152

153153
switch (m) {
154154
case IIO_CHAN_INFO_SCALE:
155-
if (val != 0)
155+
if (val != 0 || val2 == 0)
156156
return -EINVAL;
157157

158158
vref = st->int_vref_mv * 1000000LL;

0 commit comments

Comments
 (0)