[PATCH 09/12] iio: light: rohm-bu27034: Fix infinite delay on error

From: Matti Vaittinen

Date: Mon Aug 10 2026 - 03:55:55 EST


From: Matti Vaittinen <mazziesaccount@xxxxxxxxx>

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.

Signed-off-by: Matti Vaittinen <mazziesaccount@xxxxxxxxx>
Fixes: e52afbd61039 ("iio: light: ROHM BU27034 Ambient Light Sensor")
---
drivers/iio/light/rohm-bu27034.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c
index f9a421618406..e6efb8adfe37 100644
--- a/drivers/iio/light/rohm-bu27034.c
+++ b/drivers/iio/light/rohm-bu27034.c
@@ -137,6 +137,7 @@ static const struct iio_gain_sel_pair bu27034_gains[] = {
#define BU27034_MEAS_MODE_200MS 2
#define BU27034_MEAS_MODE_400MS 4

+#define BU27034_INT_TIME_MIN 55000
static const struct iio_itime_sel_mul bu27034_itimes[] = {
GAIN_SCALE_ITIME_US(400000, BU27034_MEAS_MODE_400MS, 8),
GAIN_SCALE_ITIME_US(200000, BU27034_MEAS_MODE_200MS, 4),
@@ -1162,6 +1163,15 @@ static int bu27034_buffer_thread(void *arg)
data = iio_priv(idev);

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_MIN;
+
wait_ms /= 1000;

wait_ms -= BU27034_MEAS_WAIT_PREMATURE_MS;
--
2.55.0

Attachment: signature.asc
Description: PGP signature