Skip to contentSkip to conversation

staging:iio: prevent divide by zero bugs

PATCH Applied Dan Carpenter 3 participants 3 messages Aug 18, 2012 – Aug 27, 2012

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging:iio: prevent divide by zero bugs

"val" is used as a divisor later, so we should check for zero here to avoid a division by zero.

drivers/staging/iio/imu/adis16400_core.c +2 -0
index 4ce9e3d..e803db1 100644
@@ -234,6 +234,8 @@ static ssize_t adis16400_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
drivers/staging/iio/gyro/adis16260_core.c +2 -0
index 93aa431..eb8e9d6 100644
@@ -195,6 +195,8 @@ static ssize_t adis16260_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 	if (spi_get_device_id(st->us)) {
drivers/staging/iio/adc/ad7192.c +2 -0
index 405d9a8..942b3ce 100644
@@ -647,6 +647,8 @@ static ssize_t ad7192_write_frequency(struct device *dev,
 	ret = strict_strtoul(buf, 10, &lval);
 	if (ret)
 		return ret;
+	if (lval = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 	if (iio_buffer_enabled(indio_dev)) {
drivers/staging/iio/meter/ade7759.c +2 -0
index b3f7e0f..eb0a2a9 100644
@@ -385,6 +385,8 @@ static ssize_t ade7759_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
drivers/staging/iio/meter/ade7753.c +2 -0
index f04ece7..3ccff18 100644
@@ -425,6 +425,8 @@ static ssize_t ade7753_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
drivers/staging/iio/meter/ade7754.c +2 -0
index 6cee28a..abb1e9c 100644
@@ -445,6 +445,8 @@ static ssize_t ade7754_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dan Carpenter

"val" is used as a divisor later, so we should check for zero here to avoid a division by zero.

Thanks.

Quoted 79 lines
drivers/staging/iio/imu/adis16400_core.c +2 -0
index 4ce9e3d..e803db1 100644
@@ -234,6 +234,8 @@ static ssize_t adis16400_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
drivers/staging/iio/gyro/adis16260_core.c +2 -0
index 93aa431..eb8e9d6 100644
@@ -195,6 +195,8 @@ static ssize_t adis16260_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 	if (spi_get_device_id(st->us)) {
drivers/staging/iio/adc/ad7192.c +2 -0
index 405d9a8..942b3ce 100644
@@ -647,6 +647,8 @@ static ssize_t ad7192_write_frequency(struct device *dev,
 	ret = strict_strtoul(buf, 10, &lval);
 	if (ret)
 		return ret;
+	if (lval = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 	if (iio_buffer_enabled(indio_dev)) {
drivers/staging/iio/meter/ade7759.c +2 -0
index b3f7e0f..eb0a2a9 100644
@@ -385,6 +385,8 @@ static ssize_t ade7759_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
drivers/staging/iio/meter/ade7753.c +2 -0
index f04ece7..3ccff18 100644
@@ -425,6 +425,8 @@ static ssize_t ade7753_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
drivers/staging/iio/meter/ade7754.c +2 -0
index 6cee28a..abb1e9c 100644
@@ -445,6 +445,8 @@ static ssize_t ade7754_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
maintainer Applied
#2 lore raw
In reply to Dan Carpenter
Quoted 4 lines · Dan Carpenter

"val" is used as a divisor later, so we should check for zero here to avoid a division by zero.

merged to fixes-togreg branch.
Thanks.

Quoted 84 lines
drivers/staging/iio/imu/adis16400_core.c +2 -0
index 4ce9e3d..e803db1 100644
@@ -234,6 +234,8 @@ static ssize_t adis16400_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
drivers/staging/iio/gyro/adis16260_core.c +2 -0
index 93aa431..eb8e9d6 100644
@@ -195,6 +195,8 @@ static ssize_t adis16260_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 	if (spi_get_device_id(st->us)) {
drivers/staging/iio/adc/ad7192.c +2 -0
index 405d9a8..942b3ce 100644
@@ -647,6 +647,8 @@ static ssize_t ad7192_write_frequency(struct device *dev,
 	ret = strict_strtoul(buf, 10, &lval);
 	if (ret)
 		return ret;
+	if (lval = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 	if (iio_buffer_enabled(indio_dev)) {
drivers/staging/iio/meter/ade7759.c +2 -0
index b3f7e0f..eb0a2a9 100644
@@ -385,6 +385,8 @@ static ssize_t ade7759_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
drivers/staging/iio/meter/ade7753.c +2 -0
index f04ece7..3ccff18 100644
@@ -425,6 +425,8 @@ static ssize_t ade7753_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
drivers/staging/iio/meter/ade7754.c +2 -1
index 6cee28a..abb1e9c 100644
@@ -445,6 +445,8 @@ static ssize_t ade7754_write_frequency(struct device *dev,
 	ret = strict_strtol(buf, 10, &val);
 	if (ret)
 		return ret;
+	if (val = 0)
+		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
 
--

To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html