From: sashiko-bot@kernel.org
To: "Rodrigo Alencar" <rodrigo.alencar@analog.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 4/6] iio: dac: ad5686: read_raw/write_raw: use guard(mutex)()
Date: Sun, 05 Jul 2026 11:47:45 +0000 [thread overview]
Message-ID: <20260705114746.1485F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260705-ad5686-new-features-v6-4-269594c7aae5@analog.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incorrect return value check for i2c_transfer() causes silent failures and bogus data returns.
--
commit 93acc0420c1accec74aba11d13ed25dc18d01455
Author: Rodrigo Alencar <rodrigo.alencar@analog.com>
iio: dac: ad5686: read_raw/write_raw: use guard(mutex)()
This commit transitions the read_raw and write_raw functions in the AD5686
driver to use guard(mutex) for locking. This simplifies the error paths by
allowing early returns without explicit unlock calls.
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index 75dd7921c67b8..db175e77b0b7c 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c
[ ... ]
> @@ -177,11 +178,11 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
> struct ad5686_state *st = iio_priv(indio_dev);
> int ret;
>
> + guard(mutex)(&st->lock);
> +
> switch (m) {
> case IIO_CHAN_INFO_RAW:
> - mutex_lock(&st->lock);
> ret = ad5686_read(st, chan->address);
[Severity: High]
This isn't a bug introduced by this patch, but looking at ad5686_read()
which calls into ad5686_i2c_read() for I2C devices, is there an issue with
the return value check for i2c_transfer()?
drivers/iio/dac/ad5696-i2c.c:ad5686_i2c_read() {
...
ret = i2c_transfer(i2c->adapter, msg, 2);
if (ret < 0)
return ret;
return be16_to_cpu(st->data[0].d16);
}
If the first message (write) succeeds but the second (read) fails,
i2c_transfer() returns 1 (the number of successfully transferred messages).
Since 1 is not less than 0, the check passes and the function erroneously
returns the contents of st->data[0].d16, which holds the command bytes that
were written to the buffer just before the transfer.
Should this check verify that all 2 expected messages were transferred
instead, such as checking if (ret != 2)?
> - mutex_unlock(&st->lock);
> if (ret < 0)
> return ret;
> *val = (ret >> chan->scan_type.shift) &
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260705-ad5686-new-features-v6-0-269594c7aae5@analog.com?part=4
next prev parent reply other threads:[~2026-07-05 11:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-05 11:38 [PATCH v6 0/6] New features for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
2026-07-05 11:38 ` [PATCH v6 1/6] iio: dac: ad5686: refactor command/data macros Rodrigo Alencar via B4 Relay
2026-07-05 14:24 ` Andy Shevchenko
2026-07-05 23:09 ` Jonathan Cameron
2026-07-05 23:29 ` Jonathan Cameron
2026-07-05 11:38 ` [PATCH v6 2/6] iio: dac: ad5686: introduce sync operation Rodrigo Alencar via B4 Relay
2026-07-05 11:38 ` [PATCH v6 3/6] iio: dac: ad5686: implement new sync() op for the spi bus Rodrigo Alencar via B4 Relay
2026-07-05 11:38 ` [PATCH v6 4/6] iio: dac: ad5686: read_raw/write_raw: use guard(mutex)() Rodrigo Alencar via B4 Relay
2026-07-05 11:47 ` sashiko-bot [this message]
2026-07-05 11:39 ` [PATCH v6 5/6] iio: dac: ad5686: add triggered buffer support Rodrigo Alencar via B4 Relay
2026-07-05 11:39 ` [PATCH v6 6/6] iio: dac: ad5686: add gain control support Rodrigo Alencar via B4 Relay
2026-07-05 11:50 ` sashiko-bot
2026-07-05 23:30 ` [PATCH v6 0/6] New features for the AD5686 IIO driver Jonathan Cameron
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=20260705114746.1485F1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=rodrigo.alencar@analog.com \
--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