Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maxime Chevallier" <maxime.chevallier@bootlin.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc
Date: Fri, 30 Oct 2026 16:58:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-191295@kernel.org> (raw)
In-Reply-To: <20261030164705.297354-3-maxime.chevallier@bootlin.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] iio: adc: ti-tla2528: uninitialized stack read in tla2528_read_sample()
- [Low] iio: adc: ti-tla2528: positional initializer in struct i2c_device_id table
--

commit 25a176a55c9c7afc00ecb1f3b6cd5d101cdeee77
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>

iio: adc: add driver for Texas Instruments TLA2528 adc

This commit adds an IIO ADC driver for the Texas Instruments TLA2528 8-channel
12-bit I2C ADC supporting raw channel reads.

> diff --git a/drivers/iio/adc/ti-tla2528.c b/drivers/iio/adc/ti-tla2528.c
> new file mode 100644
> index 0000000000000..287e52dc9d6d2
> --- /dev/null
> +++ b/drivers/iio/adc/ti-tla2528.c
> @@ -0,0 +1,245 @@

[ ... ]

> +static int tla2528_read_sample(const struct i2c_client *client)
> +{
> +	__be16 data;
> +	int ret;
> +
> +	ret = i2c_master_recv(client, (char *)&data, sizeof(data));
> +	if (ret < 0)
> +		return ret;
> +
> +	return be16_to_cpu(data) >> 4;
> +}

[Severity: Medium]
Can tla2528_read_sample() read uninitialized stack memory from data when
called via tla2528_read_raw() -> tla2528_read() -> tla2528_read_sample()?

i2c_master_recv() calls i2c_transfer_buffer_flags():

drivers/i2c/i2c-core-base.c:i2c_transfer_buffer_flags() {
	...
	ret = i2c_transfer(client->adapter, &msg, 1);

	/*
	 * If everything went ok (i.e. 1 msg transferred), return #bytes
	 * transferred, else error code.
	 */
	return (ret == 1) ? count : ret;
}

If the underlying I2C adapter returns 0 messages transferred from
i2c_transfer() without populating the receive buffer, i2c_master_recv()
returns 0. Because tla2528_read_sample() only checks for ret < 0, it will
proceed to shift and return the uninitialized stack variable data to
userspace.

Should this check if (ret != sizeof(data)) and return -EIO when a short read
occurs?

[ ... ]

> +static const struct i2c_device_id tla2528_id[] = {
> +	{ "tla2528" },
> +	{ }
> +};

[Severity: Low]
This isn't a bug, but should the new entry in tla2528_id in
drivers/iio/adc/ti-tla2528.c use a named initializer ({ .name = "tla2528" })
to follow the I2C subsystem convention?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261030164705.297354-1-maxime.chevallier@bootlin.com?part=2

      reply	other threads:[~2026-10-30 16:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 16:47 [PATCH v2 0/2] Add driver for the TI TLA2528 i2c ADC Maxime Chevallier
2026-10-30 16:47 ` [PATCH v2 1/2] dt-bindings: iio: adc: add Texas Instruments TLA2528 Maxime Chevallier
2026-10-30 18:34   ` Conor Dooley
2026-10-30 16:47 ` [PATCH v2 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc Maxime Chevallier
2026-10-30 16:58   ` 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-191295@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=maxime.chevallier@bootlin.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