Skip to content

Commit

Permalink
staging:iio: prevent divide by zero bugs
Browse files Browse the repository at this point in the history
"val" is used as a divisor later, so we should check for zero here to
avoid a division by zero.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
  • Loading branch information
Dan Carpenter authored and Jonathan Cameron committed Aug 27, 2012
1 parent 95d1c8c commit 50d4b30
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/staging/iio/adc/ad7192.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions drivers/staging/iio/gyro/adis16260_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions drivers/staging/iio/imu/adis16400_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions drivers/staging/iio/meter/ade7753.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions drivers/staging/iio/meter/ade7754.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions drivers/staging/iio/meter/ade7759.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 50d4b30

Please sign in to comment.