All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ti-ads7138: Disable STATS_EN bit while reading conversion results
@ 2026-06-19  7:56 Paul Geurts
  2026-06-19  8:20 ` Joshua Crofts
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Geurts @ 2026-06-19  7:56 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel,
	tobias.sperling
  Cc: Paul Geurts

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@prodrive-technologies.com>
Fixes: 93a39542d3c3 ("iio: adc: Add driver for ADS7128 / ADS7138")
---
 drivers/iio/adc/ti-ads7138.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/iio/adc/ti-ads7138.c b/drivers/iio/adc/ti-ads7138.c
index ee5c1b8e3a8e..f47cd083fd26 100644
--- a/drivers/iio/adc/ti-ads7138.c
+++ b/drivers/iio/adc/ti-ads7138.c
@@ -237,9 +237,15 @@ static int ads7138_read_raw(struct iio_dev *indio_dev,
 
 	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);
 		ret = ads7138_i2c_read_block(data->client,
 					     ADS7138_REG_RECENT_LSB_CH(chan->channel),
 					     values, ARRAY_SIZE(values));
+		/* 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;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ti-ads7138: Disable STATS_EN bit while reading conversion results
  2026-06-19  7:56 [PATCH] ti-ads7138: Disable STATS_EN bit while reading conversion results Paul Geurts
@ 2026-06-19  8:20 ` Joshua Crofts
  0 siblings, 0 replies; 2+ messages in thread
From: Joshua Crofts @ 2026-06-19  8:20 UTC (permalink / raw)
  To: Paul Geurts
  Cc: jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel,
	tobias.sperling

On Fri, 19 Jun 2026 09:56:46 +0200
Paul Geurts <paul.geurts@prodrive-technologies.com> 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@prodrive-technologies.com>
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-19  8:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-19  7:56 [PATCH] ti-ads7138: Disable STATS_EN bit while reading conversion results Paul Geurts
2026-06-19  8:20 ` Joshua Crofts

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.