Re: [PATCH v2 2/4] iio: light: rohm-bu27034: Fix infinite delay on error

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
On Fri, Aug 28, 2026 at 10:40:36AM +0300, Matti Vaittinen wrote:

> When reading an integration-time fails, the code will use error code to
> compute the sleep time.
> 
> Fix this by using the smallest integration time as a default if
> reading fails.

...

>  	wait_ms = bu27034_get_int_time(data);
> +
> +	/*
> +	 * If reading the integration time fails, default to the minimum so we
> +	 * don't lose samples. This may waste CPU cycles, but as a hardening
> +	 * against theoretical, once-in-a-blue-moon error, this should be Ok.
> +	 */
> +	if (wait_ms < 0)
> +		wait_ms = BU27034_INT_TIME_US_MIN;
> +
>  	wait_ms /= 1000;

With the above being open coded the _ms feels not right.
I would expect the TIME_MIN to be in MS from the start
(and for the consistency's sake with the below) and having
all this to be written like

	ret = bu27034_get_int_time(data);
	if (ret < 0)
		wait_ms = _MS_MIN;
	else
		wait_ms = ret / USEC_PER_MSEC;

>  	wait_ms -= BU27034_MEAS_WAIT_PREMATURE_MS;

-- 
With Best Regards,
Andy Shevchenko
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.