Re: [PATCH v2 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq
From: Andy Shevchenko
Date: Thu Feb 12 2026 - 05:56:33 EST
On Thu, Feb 12, 2026 at 02:26:53PM +0800, Yasin Lee wrote:
> Avoid division by zero when sampling frequency is unspecified by
> falling back to a default 100ms sampling period.
...
> - period_ms = div_u64(NANO, (val * MEGA + val2));
> + if (val || val2)
> + period_ms = div_u64(NANO, (val * MEGA + val2));
While at it, drop unneeded parentheses.
> + else
> + /* Fallback to a safe default sampling period */
> + period_ms = 100;
Not sure about this. Perhaps we should rather do
if (!val || !val2)
return -EINVAL;
?
--
With Best Regards,
Andy Shevchenko