[PATCH 04/12] iio: adc: rohm-bd79124: Catch regmap errors at measurement start/stop

From: Matti Vaittinen

Date: Mon Aug 10 2026 - 03:52:26 EST


From: Matti Vaittinen <mazziesaccount@xxxxxxxxx>

The bd79124_start_measurement() and bd79124_stop_measurement() ignore
errors from the regmap reads, causing potential use of uninitialized
stack variable when deciding whether the measurement is already
started/stopped. The bd79124_stop_measurement() may also ignore failure
to clear the sequencer state bits, which may make the hardware to ignore
the setting and leave hardware and driver states out of sync.

Check the return value and bail-out if error is detected.

Signed-off-by: Matti Vaittinen <mazziesaccount@xxxxxxxxx>
Fixes: 3f57a3b9ab74 ("iio: adc: Support ROHM BD79124 ADC")
---
drivers/iio/adc/rohm-bd79124.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/iio/adc/rohm-bd79124.c b/drivers/iio/adc/rohm-bd79124.c
index 84ac7fc94581..600354fe0ee0 100644
--- a/drivers/iio/adc/rohm-bd79124.c
+++ b/drivers/iio/adc/rohm-bd79124.c
@@ -382,6 +382,9 @@ static int bd79124_start_measurement(struct bd79124_data *data, int chan)

/* See if already started */
ret = regmap_read(data->map, BD79124_REG_AUTO_CHANNELS, &val);
+ if (ret)
+ return ret;
+
if (val & BIT(chan))
return 0;

@@ -421,11 +424,16 @@ static int bd79124_stop_measurement(struct bd79124_data *data, int chan)

/* See if already stopped */
ret = regmap_read(data->map, BD79124_REG_AUTO_CHANNELS, &enabled_chans);
+ if (ret)
+ return ret;
+
if (!(enabled_chans & BIT(chan)))
return 0;

ret = regmap_clear_bits(data->map, BD79124_REG_SEQ_CFG,
BD79124_MSK_SEQ_START);
+ if (ret)
+ return ret;

/* Clear the channel from the measured channels */
enabled_chans &= ~BIT(chan);
--
2.55.0

Attachment: signature.asc
Description: PGP signature