From: sashiko-bot@kernel.org
To: "Stefan Popa" <stefan.popa@analog.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 2/2] iio: adc: add MAX40080 current-sense amplifier driver
Date: Wed, 15 Jul 2026 06:46:44 +0000 [thread overview]
Message-ID: <20260715064644.F02291F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260715063652.368501-3-stefan.popa@analog.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing lock protection around `st->range` and `st->oversampling_ratio` updates causes hardware state desynchronization and torn reads.
--
--- Patch [2]: [PATCH v3 2/2] iio: adc: add MAX40080 current-sense amplifier driver ---
commit 6f9d9d6fa7d25018a7143edc9a8c9183463f1900
Author: Stefan Popa <stefan.popa@analog.com>
iio: adc: add MAX40080 current-sense amplifier driver
The MAX40080 is a bidirectional current-sense amplifier with an
integrated 12-bit ADC and an I2C/SMBus interface. It measures the
voltage across an external shunt resistor and the input bus voltage,
storing the results in an internal FIFO.
Link: https://www.analog.com/media/en/technical-documentation/data-sheets/MAX40080.pdf
> diff --git a/drivers/iio/adc/max40080.c b/drivers/iio/adc/max40080.c
> new file mode 100644
> index 0000000000000..a0c1144cfda7c
> --- /dev/null
> +++ b/drivers/iio/adc/max40080.c
[ ... ]
> +static int max40080_set_range(struct max40080_state *st, unsigned int range)
> +{
> + int ret;
> +
> + ret = max40080_update_bits(st, MAX40080_REG_CFG, MAX40080_CFG_RANGE_MSK,
> + FIELD_PREP(MAX40080_CFG_RANGE_MSK, range));
> + if (ret)
> + return ret;
> +
> + st->range = range;
[Severity: Medium]
Could a race condition here cause the software cache to become desynchronized
with the hardware state?
Since max40080_update_bits() releases st->lock before returning, concurrent
writes to the scale attribute could interleave their hardware updates and
software cache updates, leaving the hardware set to one range and the cache
set to another.
> +
> + return 0;
> +}
[ ... ]
> +static int max40080_set_oversampling_ratio(struct max40080_state *st, int val)
> +{
> + int filter;
> + int ret;
> +
> + filter = max40080_oversampling_to_filter(val);
> + if (filter < 0)
> + return filter;
> +
> + ret = max40080_update_bits(st, MAX40080_REG_CFG, MAX40080_CFG_FILTER_MSK,
> + FIELD_PREP(MAX40080_CFG_FILTER_MSK, filter));
> + if (ret)
> + return ret;
> +
> + st->oversampling_ratio = val;
[Severity: Medium]
Similar to st->range above, could st->oversampling_ratio become desynchronized
with the hardware state due to being updated outside the lock?
> +
> + return 0;
> +}
> +
> +static int max40080_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val, int *val2, long mask)
> +{
> + struct max40080_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + switch (mask) {
[ ... ]
> + case IIO_CHAN_INFO_SCALE:
> + /*
> + * The selectable current-sense range is exposed through
> + * scale: each RANGE setting has its own precomputed
> + * mA-per-code value. Userspace picks the range by writing
> + * the matching scale.
> + */
> + switch (chan->type) {
> + case IIO_CURRENT:
> + *val = st->current_scale[st->range][0];
> + *val2 = st->current_scale[st->range][1];
[Severity: Medium]
Can this cause a torn read if st->range is updated concurrently?
Since st->range is used twice as an array index without taking st->lock,
concurrent writes could cause val and val2 to be mixed from different ranges.
> + return IIO_VAL_INT_PLUS_NANO;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260715063652.368501-1-stefan.popa@analog.com?part=2
next prev parent reply other threads:[~2026-07-15 6:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 6:36 [PATCH v3 0/2] iio: adc: add MAX40080 current-sense amplifier driver Stefan Popa
2026-07-15 6:36 ` [PATCH v3 1/2] dt-bindings: iio: adc: add maxim,max40080 Stefan Popa
2026-07-15 6:45 ` sashiko-bot
2026-07-15 6:36 ` [PATCH v3 2/2] iio: adc: add MAX40080 current-sense amplifier driver Stefan Popa
2026-07-15 6:46 ` sashiko-bot [this message]
2026-07-15 8:34 ` Andy Shevchenko
2026-07-15 6:51 ` [PATCH v3 0/2] " Andy Shevchenko
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=20260715064644.F02291F000E9@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 \
--cc=stefan.popa@analog.com \
/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