Skip to contentSkip to conversation

ad7780: fix division by zero in ad7780_write_raw()

PATCH Applied Zicheng Qu 2 participants 3 messages Oct 28, 2024 – Oct 31, 2024

Subsystems (3)
lore
Share & tools
lore

Zicheng Qu

author
#0 lore raw

PATCH 1/1 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 9085daa4abcc ("staging: iio: ad7780: add gain & filter gpio support")
---
 drivers/iio/adc/ad7780.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7780.c +1 -1
index e9b0c577c9cc..8ccb74f47030 100644
@@ -152,7 +152,7 @@ static int ad7780_write_raw(struct iio_dev *indio_dev,
 
 	switch (m) {
 	case IIO_CHAN_INFO_SCALE:
-		if (val != 0)
+		if (val != 0 || val2 == 0)
 			return -EINVAL;
 
 		vref = st->int_vref_mv * 1000000LL;
Signature · 1 line
2.34.1
maintainer Applied
#2 lore raw
In reply to Zicheng Qu
Quoted 8 lines · On Mon, 28 Oct 2024 14:20:27 +0000 Zicheng Qu <[email protected]> wrote:

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 9085daa4abcc ("staging: iio: ad7780: add gain & filter gpio support")

Applied to the fixes-togreg branch of iio.git.

I might end up dragging this in to my queue for the coming merge window if I don't get time to do another fixes pull request in the next few days.

Jonathan

Quoted 17 lines
---
 drivers/iio/adc/ad7780.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7780.c +1 -1
index e9b0c577c9cc..8ccb74f47030 100644
@@ -152,7 +152,7 @@ static int ad7780_write_raw(struct iio_dev *indio_dev,
 
 	switch (m) {
 	case IIO_CHAN_INFO_SCALE:
-		if (val != 0)
+		if (val != 0 || val2 == 0)
 			return -EINVAL;
 
 		vref = st->int_vref_mv * 1000000LL;