Re: [PATCH] ti-ads7138: Disable STATS_EN bit while reading conversion results

From: Joshua Crofts

Date: Fri Jun 19 2026 - 04:21:01 EST


On Fri, 19 Jun 2026 09:56:46 +0200
Paul Geurts <paul.geurts@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> The device might update channel data while it's read by the host,
> providing a data race. Disable the update of the channel stats before
> reading the values.
>
> Signed-off-by: Paul Geurts <paul.geurts@xxxxxxxxxxxxxxxxxxxxxxxxx>
> Fixes: 93a39542d3c3 ("iio: adc: Add driver for ADS7128 / ADS7138")
> ---

Don't forget to add the iio: prefix to the subject/commit title.

> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> + /* Disable statistics update so the value is not updated mid read */
> + ret = ads7138_i2c_clear_bit(data->client, ADS7138_REG_GENERAL_CFG,
> + ADS7138_GENERAL_CFG_STATS_EN);

You're not checking the value of ret here :(

> ret = ads7138_i2c_read_block(data->client,
> ADS7138_REG_RECENT_LSB_CH(chan->channel),
> values, ARRAY_SIZE(values));

Additionally, since you've added a i2c_set_bit function below,
you're not checking the return value of the i2c_read_block function.
Instead of returning the return value if an error occurs, the values
variable will remain uninitialized, causing a kernel stack leak.

> + /* Enable statistics update after read */
> + ret = ads7138_i2c_set_bit(data->client, ADS7138_REG_GENERAL_CFG,
> + ADS7138_GENERAL_CFG_STATS_EN);
> if (ret)
> return ret;
>

--
Kind regards

CJD