Re: [PATCH v4 1/4] iio: light: tsl2591: don't divide by zero
From: Jonathan Cameron
Date: Thu Oct 22 2026 - 23:14:12 EST
On Thu, 22 Oct 2026 20:56:40 +0200
Jan Remes <ciakval@xxxxxxxxx> wrote:
> From: Jan Remes <jan.remes@xxxxxxxxxxxxxxx>
>
> The TSL2591 has two raw light channels - CH0 and CH1. The algorithm for
> calculating illumination from the raw channels requires division by CH0
> (which can be zero) and by "counts per lux" (CPL) value which is also zero
> for (gain = LOW, integration time <= 400 ms).
>
> Furthermore, the algorithm assumes CH0 > CH1, which can be violated in
> almost complete darkness.
>
> As a result, reading from 'in_illuminance_input' results in
> division-by-zero whenever CH0 is 0 (complete darkness) or whenever the
> parameters result in CPL being zero. This results in kernel oops on
> x86_64 and in reading the value as 0 on arm64.
>
> Fix that by:
> - reporting CH0 <= CH1 as zero (catches also CH0 = 0)
> - updating the lux algorithm to only do the division at the end
>
> Fixes: 2335f0d7c790 ("iio: light: Added AMS tsl2591 driver implementation")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Martin Triska <martin.triska@xxxxxxxxxxxxxxx>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Signed-off-by: Jan Remes <jan.remes@xxxxxxxxxxxxxxx>
Applied to the fixes-togreg branch of iio.git
Thanks,
Jonathan