Re: [PATCH] iio: chemical: scd30: Cleanup initializations in scd30_float_to_fp()
From: Andy Shevchenko
Date: Sun May 10 2026 - 05:17:46 EST
On Fri, May 08, 2026 at 05:55:00PM -0500, Maxwell Doose wrote:
> The current variable declaration and initializations are barely readable
> and use comma separations across multiple lines. Refactor the
> initializations so that mantissa and exp have separate declarations and
> sign gets initialized later.
The change LGTM,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
...
> ps:
> Hi Jonathan, I noticed a potential divide-by-zero bug on line 241 in
> scd30_read_raw(), where the value of tmp is dictated by hardware.
> If the scd30_command_read() call on line 236 assigns 0 to tmp, then
> when we run:
> *val2 = 1000000000 / tmp;
> we'll get a divide-by-zero. Will send a patch for this later.
Have you checked the Clang and GCC compiled code in that cases?
Do they put anything interesting in the binary? (I.o.w. can they prove
the division-by-zero at compile-time?)
See the (somehow) related case in the 7e5c0f97c66a ("iio: adc: nxp-sar-adc:
Avoid division by zero"), which is in Linux Next only (for now).
--
With Best Regards,
Andy Shevchenko