Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 7/8] iio: adc: ti-ads112c14: implement gain on internal short SYS_MON channel
Date: Thu, 25 Jun 2026 22:08:26 +0000	[thread overview]
Message-ID: <20260625220826.7323A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260625-iio-adc-ti-ads122c14-v2-7-ceb9b0b561cb@baylibre.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unlocked concurrent accesses to `gain_val` variables can result in data races and potentially corrupted scale values being returned to userspace.
--

commit d2600e3b47039aca86a7fafcbbec65c4180a38f5
Author: David Lechner (TI) <dlechner@baylibre.com>

iio: adc: ti-ads112c14: implement gain on internal short SYS_MON channel

Implement support for the programmable gain amplifier on the internal short
SYS_MON channel. This channel is used for calibration, so it is useful to be
able to set the PGA to the same gain as the external channels.

> diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
> index c61d472447325..0e775dbc8d50b 100644
> --- a/drivers/iio/adc/ti-ads112c14.c
> +++ b/drivers/iio/adc/ti-ads112c14.c
[ ... ]
> @@ -371,6 +401,17 @@ static int ads112c14_read_raw(struct iio_dev *indio_dev,
>  			return IIO_VAL_FRACTIONAL_LOG2;
>  		}
>  
> +		if (chan->channel == ADS112C14_SYS_MON_CHANNEL_SHORT) {
> +			u8 idx = data->sys_mon_chan_short_gain_val;
> +
> +			scale_avail = data->sys_mon_chan_short_scale_available[idx];
> +
> +			*val = scale_avail[0];
> +			*val2 = scale_avail[1];
> +
> +			return IIO_VAL_INT_PLUS_NANO;
> +		}
> +

[Severity: Medium]
Is it possible for a concurrent write from ads112c14_write_raw() to cause a
data race here?

Since this read side in ads112c14_read_raw() does not acquire the IIO direct
mode lock or use READ_ONCE(), the compiler could reload 
data->sys_mon_chan_short_gain_val.

If the value gets reloaded between the assignments of *val and *val2, the
function might fetch the integer and fractional parts from different gain
configurations, returning a corrupted scale to userspace.

[ ... ]
> +static int ads112c14_write_raw(struct iio_dev *indio_dev,
> +			       struct iio_chan_spec const *chan, int val,
> +			       int val2, long mask)
> +{
[ ... ]
> +		IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> +		if (IIO_DEV_ACQUIRE_FAILED(claim))
> +			return -EBUSY;
> +
> +		for (u32 i = 0; i < ARRAY_SIZE(ads112c14_pga_gains_x10); i++) {
> +			if (val == scale_avail[i][0] && val2 == scale_avail[i][1]) {
> +				*gain_val = i;
> +				return 0;
> +			}
> +		}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260625-iio-adc-ti-ads122c14-v2-0-ceb9b0b561cb@baylibre.com?part=7

  reply	other threads:[~2026-06-25 22:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 21:55 [PATCH v2 0/8] iio: adc: new ti-ads112c14 driver David Lechner
2026-06-25 21:55 ` [PATCH v2 1/8] dt-bindings: iio: adc: Add reference-sources property David Lechner
2026-06-26 16:12   ` Conor Dooley
2026-06-25 21:55 ` [PATCH v2 2/8] dt-bindings: iio: adc: Add excitation current sources properties David Lechner
2026-06-26 16:10   ` Conor Dooley
2026-06-25 21:55 ` [PATCH v2 3/8] dt-bindings: iio: adc: Add burn-out current properties David Lechner
2026-06-26 16:12   ` Conor Dooley
2026-06-25 21:55 ` [PATCH v2 4/8] dt-bindings: iio: adc: add input-channel-rotation property David Lechner (TI)
2026-06-26 16:14   ` Conor Dooley
2026-06-26 18:27     ` David Lechner
2026-06-25 21:55 ` [PATCH v2 5/8] dt-bindings: iio: adc: add ti,ads122c14 David Lechner (TI)
2026-06-25 22:12   ` sashiko-bot
2026-06-26 16:18   ` Conor Dooley
2026-06-26 18:35     ` David Lechner
2026-06-25 21:55 ` [PATCH v2 6/8] iio: adc: add ti-ads112c14 driver David Lechner (TI)
2026-06-25 22:07   ` sashiko-bot
2026-06-25 21:55 ` [PATCH v2 7/8] iio: adc: ti-ads112c14: implement gain on internal short SYS_MON channel David Lechner (TI)
2026-06-25 22:08   ` sashiko-bot [this message]
2026-06-25 21:55 ` [PATCH v2 8/8] iio: adc: ti-ads112c14: add measurement channel support David Lechner (TI)
2026-06-25 22:11   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260625220826.7323A1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox