From: sashiko-bot@kernel.org
To: "Piyush Patle" <piyushpatle228@gmail.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v10 10/11] iio: adc: hx711: pass iio_chan_spec to hx711_reset_read
Date: Mon, 25 May 2026 11:25:15 +0000 [thread overview]
Message-ID: <20260525112515.7E9671F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260525105127.180156-11-piyushpatle228@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing `iio_device_claim_direct_mode()` allows concurrent sysfs reads to disrupt triggered buffer continuous sampling.
- [High] Out-of-bounds Array Write in `hx711_trigger()` when the timestamp channel is enabled.
--
commit b8324538619dcb536bed461da5b5bd5e89ca409b
Author: Piyush Patle <piyushpatle228@gmail.com>
iio: adc: hx711: pass iio_chan_spec to hx711_reset_read
Change hx711_reset_read() to accept the channel descriptor directly and
update its callers accordingly. Split the existing HX711 channel-selection
work into a small helper so a later variant-specific change can add a
matching helper without growing hx711_reset_read() further.
> diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
> --- a/drivers/iio/adc/hx711.c
> +++ b/drivers/iio/adc/hx711.c
[ ... ]
> @@ -300,7 +315,7 @@ static int hx711_read_raw(struct iio_dev *indio_dev,
> case IIO_CHAN_INFO_RAW:
> mutex_lock(&hx711_data->lock);
>
> - *val = hx711_reset_read(hx711_data, chan->channel);
> + *val = hx711_reset_read(hx711_data, chan);
>
> mutex_unlock(&hx711_data->lock);
>
[Severity: High]
This is a pre-existing issue, but does this function need to call
iio_device_claim_direct_mode() before accessing the hardware?
If a triggered buffer is active, couldn't a concurrent sysfs read to
in_voltage0_raw take the lock, wait for the device to be ready, and perform
a hardware read?
This might steal a sample from the continuous buffer stream, introduce
massive timing jitter due to gain changes, and disrupt the functional
behavior of the triggered buffer.
[ ... ]
> @@ -390,8 +405,8 @@ static irqreturn_t hx711_trigger(int irq, void *p)
> memset(&hx711_data->buffer, 0, sizeof(hx711_data->buffer));
>
> iio_for_each_active_channel(indio_dev, i) {
> - hx711_data->buffer.channel[j] = hx711_reset_read(hx711_data,
> - indio_dev->channels[i].channel);
> + hx711_data->buffer.channel[j] =
> + hx711_reset_read(hx711_data, &indio_dev->channels[i]);
> j++;
> }
>
[Severity: High]
This isn't a bug introduced by this patch, but does this loop correctly
handle the timestamp channel?
Since iio_for_each_active_channel() iterates over all bits set in the
active_scan_mask, wouldn't it include the soft timestamp channel if enabled
by userspace?
If the loop doesn't explicitly skip the timestamp channel, it appears it
would treat it as an ADC channel and call hx711_reset_read() on it, wasting
time on a hardware conversion.
Furthermore, when j reaches 2, writing to channel[j] would be an
out-of-bounds array access on the 2-element array, potentially triggering a
kernel panic when compiled with UBSAN bounds checking.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260525105127.180156-1-piyushpatle228@gmail.com?part=10
next prev parent reply other threads:[~2026-05-25 11:25 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 10:51 [PATCH v10 00/11] iio: adc: Add support for AVIA HX710B ADC Piyush Patle
2026-05-25 10:51 ` [PATCH v10 01/11] dt-bindings: iio: adc: hx711: clean up existing binding text Piyush Patle
2026-05-25 10:51 ` [PATCH v10 02/11] dt-bindings: iio: adc: hx711: add VSUP supply property Piyush Patle
2026-05-25 10:58 ` sashiko-bot
2026-05-27 17:34 ` Jonathan Cameron
2026-05-25 10:51 ` [PATCH v10 03/11] dt-bindings: iio: adc: hx711: add RATE GPIO property Piyush Patle
2026-05-25 10:51 ` [PATCH v10 04/11] dt-bindings: iio: adc: hx711: add HX710B support Piyush Patle
2026-05-25 11:11 ` sashiko-bot
2026-05-25 17:01 ` Conor Dooley
2026-05-27 17:41 ` Jonathan Cameron
2026-05-28 8:54 ` Conor Dooley
2026-05-28 13:08 ` Jonathan Cameron
2026-05-28 14:09 ` Conor Dooley
2026-05-27 17:37 ` Jonathan Cameron
2026-05-25 10:51 ` [PATCH v10 05/11] iio: adc: hx711: move scale computation to per-device storage Piyush Patle
2026-05-25 10:51 ` [PATCH v10 06/11] iio: adc: hx711: introduce hx711_chip_info structure Piyush Patle
2026-05-25 11:34 ` sashiko-bot
2026-05-25 10:51 ` [PATCH v10 07/11] iio: adc: hx711: pass trailing pulse count into hx711_read Piyush Patle
2026-05-25 11:10 ` sashiko-bot
2026-05-25 10:51 ` [PATCH v10 08/11] iio: adc: hx711: split variable assignments in hx711_read and hx711_reset Piyush Patle
2026-05-25 10:51 ` [PATCH v10 09/11] iio: adc: hx711: localize loop iterators in hx711_read Piyush Patle
2026-05-25 10:51 ` [PATCH v10 10/11] iio: adc: hx711: pass iio_chan_spec to hx711_reset_read Piyush Patle
2026-05-25 11:25 ` sashiko-bot [this message]
2026-05-25 10:51 ` [PATCH v10 11/11] iio: adc: hx711: add support for HX710B Piyush Patle
2026-05-25 11:33 ` sashiko-bot
2026-05-27 17:54 ` Jonathan Cameron
2026-05-27 17:32 ` [PATCH v10 00/11] iio: adc: Add support for AVIA HX710B ADC Jonathan Cameron
2026-05-27 17:45 ` 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=20260525112515.7E9671F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=piyushpatle228@gmail.com \
--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