Re: [PATCH v3 3/3] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq()

From: Andy Shevchenko

Date: Thu Dec 03 2026 - 06:51:41 EST


On Wed, Dec 02, 2026 at 08:21:12PM +0000, Lee Jones wrote:
> isl29501_set_freq() computes freq = val * 1000000 + val2 % 1000000 in a
> signed 32-bit int and passes it directly to do_div() without checking
> for zero or negative inputs. Writing 0 to the sampling_frequency
> attribute triggers a division by zero in the kernel, while valid
> frequencies above 2147 Hz up to the sensor's 2222 Hz limit overflow
> signed int.
>
> Validate val and val2 up front so that the requested frequency lies
> within (0, 2222] Hz with val2 in [0, MICROHZ_PER_HZ), compute freq as
> an unsigned int using MICROHZ_PER_HZ, and return -ERANGE otherwise.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>

...

> +++ b/drivers/iio/proximity/isl29501.c

> #include <linux/iio/trigger_consumer.h>
> #include <linux/iio/buffer.h>
> #include <linux/iio/triggered_buffer.h>
> +#include <linux/units.h>

Yes, the headers are mess in the driver, but please make them as

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/err.h>
#include <linux/units.h>

#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/buffer.h>
#include <linux/iio/triggered_buffer.h>

(this will be a minimal intrusion with a small step towards an improvement).

--
With Best Regards,
Andy Shevchenko