Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Akhilesh Patil" <akhilesh.patil@linux.dev>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 2/2] iio: chemical: acd10: Add driver for ACD10 CO2 sensor
Date: Sun, 22 Nov 2026 06:40:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-227768@kernel.org> (raw)
In-Reply-To: <07fe3a575ad86493076d5061ed71c15e7b837a10.1795326744.git.akhilesh.patil@linux.dev>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] iio: chemical: acd10: race and OOB write in acd10_receive_buf()
- [Medium] iio: chemical: acd10: missing MODULE_DEVICE_TABLE() for OF
  matching
- [Medium] iio: chemical: acd10: missing vcc-supply enable in
  acd10_probe()
--

commit 2784731160894116b07cdc2f499cc0eb12597983
Author: Akhilesh Patil <akhilesh.patil@linux.dev>

iio: chemical: acd10: Add driver for ACD10 CO2 sensor

This commit adds an IIO driver for the Aosong ASAIR ACD10 carbon dioxide
sensor communicating over UART via the serdev interface.

> diff --git a/drivers/iio/chemical/acd10.c b/drivers/iio/chemical/acd10.c
> new file mode 100644
> index 0000000000000..b92f01e7bf4a1
> --- /dev/null
> +++ b/drivers/iio/chemical/acd10.c
> @@ -0,0 +1,365 @@

[ ... ]

> +struct acd10_state {
> +	struct serdev_device *serdev;
> +
> +	/* Lock to acquire during CMD/RESP sequence */
> +	struct mutex lock;
> +	struct completion buf_ready;
> +
> +	/* Single buffer to hold tx and rx data */
> +	u8 buf[16];
> +	u8 buf_idx;
> +	u8 rx_expected_len;
> +
> +	u8 sw_rev[16];
> +	u8 inst_num[16];
> +};

[ ... ]

> +static int acd10_serdev_transfer(struct iio_dev *indio_dev, enum acd10_cmds cmd)
> +{
> +	struct acd10_state *drv_state = iio_priv(indio_dev);
> +	struct serdev_device *serdev = drv_state->serdev;
> +	struct device *dev = &indio_dev->dev;
> +	int ret;
> +
> +	/* Prepare transmit buffer along with checksum */
> +	drv_state->buf[0] = ACD10_FRAME_START;
> +	drv_state->buf[1] = ACD10_FRAME_FIXED_CODE;
> +	drv_state->buf[ACD10_FRAME_DATA_LEN_IDX] = cmd_info[cmd].tx_data_len;
> +	drv_state->buf[ACD10_FRAME_CMD_CODE_IDX] = cmd_info[cmd].cmd_code;
> +	drv_state->buf[cmd_info[cmd].tx_frame_len - 1] =
> +		acd10_get_checksum(drv_state->buf, cmd_info[cmd].tx_frame_len);
> +	drv_state->buf_idx = 0;
> +	drv_state->rx_expected_len = cmd_info[cmd].rx_frame_len;
> +	reinit_completion(&drv_state->buf_ready);
> +
> +	/* Transmit the buffer over serdev */
> +	ret = serdev_device_write(serdev, drv_state->buf, cmd_info[cmd].tx_frame_len,
> +				  ACD10_SERDEV_TIMEOUT);
> +	if (ret < 0)
> +		return ret;
> +	if (ret != cmd_info[cmd].tx_frame_len)
> +		return -EIO;
> +
> +	/* Read the received bytes in buffer */
> +	ret = wait_for_completion_interruptible_timeout(&drv_state->buf_ready,
> +							ACD10_SERDEV_TIMEOUT);
> +	if (ret < 0)
> +		return ret;
> +	if (!ret)
> +		return -ETIMEDOUT;

[ ... ]

> +static size_t acd10_receive_buf(struct serdev_device *serdev,
> +				const u8 *data, size_t len)
> +{
> +	struct iio_dev *indio_dev = serdev_device_get_drvdata(serdev);
> +	struct acd10_state *drv_state = iio_priv(indio_dev);
> +	size_t consume = len;
> +	int i = 0;
> +
> +	while (drv_state->rx_expected_len && (consume > 0)) {
> +		drv_state->buf[drv_state->buf_idx++] = data[i++];
> +		consume -= 1;
> +		drv_state->rx_expected_len -= 1;
> +	}
> +
> +	if (drv_state->rx_expected_len == 0) {
> +		drv_state->buf_idx = 0;
> +		complete(&drv_state->buf_ready);
> +	}
> +
> +	return len;
> +}

[Severity: High]
Can a late UART response after a signal-interrupted or timed-out read race
with the next transfer and overflow drv_state->buf[16]?

If wait_for_completion_interruptible_timeout() returns early on a signal or
timeout, drv_state->rx_expected_len is left non-zero while the sensor is
still transmitting at 1200 baud.  acd10_receive_buf() runs without locking
or a bounds check against sizeof(drv_state->buf):

CPU0                                  CPU1 (tty flip workqueue)
acd10_serdev_transfer()
  wait_for_completion_...()
  -> -ERESTARTSYS (rx_expected_len=9)
acd10_serdev_transfer()
  drv_state->buf_idx = 0;
                                      acd10_receive_buf()
                                        /* 8 late bytes arrive */
                                        buf_idx becomes 8
  drv_state->rx_expected_len = 9;
                                      acd10_receive_buf()
                                        /* 9 new bytes arrive */
                                        drv_state->buf[16] = ...
                                          <-- OOB write into drv_state

Even when buf_idx does not overflow, late bytes arriving while
rx_expected_len is still non-zero overwrite drv_state->buf[0..4] while the
next TX command and checksum are being built, and shift subsequent RX
frames out of alignment because acd10_receive_buf() does not resynchronize
on ACD10_FRAME_START.

[ ... ]

> +	ret = acd10_get_sw_rev(indio_dev);
> +	if (ret)
> +		return ret;
> +
> +	ret = acd10_get_instrument_num(indio_dev);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_iio_device_register(dev, indio_dev);
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}

[Severity: Medium]
Should acd10_probe() enable the vcc-supply regulator before talking to the
sensor?

The DT binding in Documentation/devicetree/bindings/iio/chemical/aosong,acd10.yaml
defines vcc-supply, so on boards where that rail is not always-on,
acd10_get_sw_rev() will time out unless acd10_probe() enables it (for
example with devm_regulator_get_enable(dev, "vcc")).

> +
> +static const struct of_device_id acd10_of_match_table[] = {
> +	{ .compatible = "aosong,acd10", },
> +	{ }
> +};

[Severity: Medium]
Is MODULE_DEVICE_TABLE(of, acd10_of_match_table) missing here?  Without it,
building with CONFIG_ACD10=m will not emit the OF modalias for automatic
module loading.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795326744.git.akhilesh.patil@linux.dev?part=2

      reply	other threads:[~2026-11-22  6:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22  6:30 [PATCH 0/2] iio: chemical: Add driver and bindings for acd10 Akhilesh Patil
2026-11-22  6:31 ` [PATCH 1/2] dt-bindings: iio: chemical: Add aosong acd10 Akhilesh Patil
2026-11-22  6:32 ` [PATCH 2/2] iio: chemical: acd10: Add driver for ACD10 CO2 sensor Akhilesh Patil
2026-11-22  6:40   ` sashiko-bot [this message]

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=sashiko-outbox-227768@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akhilesh.patil@linux.dev \
    --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