[PATCH 04/12] iio: adc: rohm-bd79124: Catch regmap errors at measurement start/stop
Matti Vaittinen <[email protected]>
| Newsgroups | org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <fc198eaf83319548317611ee128e78a542567156.1786347811.git.mazziesaccount@gmail.com> |
From: Matti Vaittinen <[email protected]> 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 <[email protected]> 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
signature.asc
(application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmp5gvgACgkQeFA3/03a ocXj9wgAsMAFnfVAOeOdsfa0tfIZGO/qSJXyFP6ibIqvktIBFvXpYla2serHEM7O vovXSSiycWTWhgD7WodTONbFi2a9z3J841z9DTfdxCTr26lyh1ku8nCHPjiOzXAA qhH5eS2sxoB8sUm2b+AFW/nqbLlhMwmad8TjKQE+0+4gjAD64WCfO1mvvs/4TEvU dKEoemAJZVJle4uWC49MFOvXolRh4eeSO2145WsgSFjmRxeYTgOzUQNo2Ghb3H/H 4Nk25OCaGY+y3PUI2plH4h1p1LDorVU81XdE182aAMZGRf9M+wVMxbEPaqQkpMOb N9THE5BgCTWVJRgQ/qRDOz8C/W0hfw== =esq7 -----END PGP SIGNATURE-----