All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 6/8] iio: adc: add ti-ads112c14 driver
Date: Thu, 25 Jun 2026 22:07:10 +0000	[thread overview]
Message-ID: <20260625220711.1B8F21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260625-iio-adc-ti-ads122c14-v2-6-ceb9b0b561cb@baylibre.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Short I2C reads lead to the use of uninitialized stack memory for ADC readings.
- [High] The driver inadvertently sets the device into Continuous Conversion mode instead of the intended Single-Shot mode.
--

commit 610f816911f47ce29d3c83f300222d6ab72f8820
Author: David Lechner (TI) <dlechner@baylibre.com>

iio: adc: add ti-ads112c14 driver

Add a new driver for the TI ADS112C14/ADS122C14 ADC chips.

This first step is adding a very basic driver that only supports power
on/reset and reading the system monitor channels.

> diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
> new file mode 100644
> index 0000000000000..c61d472447325
> --- /dev/null
> +++ b/drivers/iio/adc/ti-ads112c14.c

[ ... ]

> +static int ads112c14_single_conversion(struct ads112c14_data *data,
> +				       const struct iio_chan_spec *chan,
> +				       u8 *buf)
> +{

[ ... ]

> +	return i2c_smbus_read_i2c_block_data(client, ADS112C14_CMD_RDATA,
> +					     BITS_TO_BYTES(data->chip_info->resolution_bits),
> +					     buf);
> +}
> +
> +static int ads112c14_read_raw(struct iio_dev *indio_dev,
> +			      struct iio_chan_spec const *chan, int *val,
> +			      int *val2, long mask)
> +{

[ ... ]

> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW: {
> +		u8 buf[3];
> +		int ret;
> +
> +		if (!iio_device_claim_direct(indio_dev))
> +			return -EBUSY;
> +
> +		ret = ads112c14_single_conversion(data, chan, buf);
> +		iio_device_release_direct(indio_dev);
> +		if (ret < 0)
> +			return ret;

[Severity: High]
Does this code handle short I2C reads correctly?

i2c_smbus_read_i2c_block_data() returns the positive byte count on success.
If the device returns fewer bytes than requested, ret will be positive but
less than BITS_TO_BYTES(data->chip_info->resolution_bits).

Since ads112c14_read_raw() only checks if (ret < 0), won't a short read
bypass error handling and cause it to process uninitialized stack memory from
buf, leading to an information leak and corrupted ADC readings?

> +
> +		switch (data->chip_info->resolution_bits) {
> +		case 16:
> +			*val = get_unaligned_be16(buf);

[ ... ]

> +static int ads112c14_probe(struct i2c_client *client)
> +{

[ ... ]

> +	/* Place in single-shot conversion mode to make ready for raw read. */
> +	ret = regmap_set_bits(data->regmap, ADS112C14_REG_DEVICE_CFG,
> +			      ADS112C14_DEVICE_CFG_CONV_MODE);

[Severity: High]
Does setting ADS112C14_DEVICE_CFG_CONV_MODE actually put the device into
continuous conversion mode instead of the intended single-shot mode?

According to the comment, the intention is to use single-shot mode (which is
typically the default value of 0). Setting the bit to 1 appears to enable
continuous conversion mode, which could cause hardware race conditions and
corrupted data when multiplexer settings are changed for new sysfs readings.

> +	if (ret)
> +		return ret;
> +
> +	indio_dev->name = info->name;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260625-iio-adc-ti-ads122c14-v2-0-ceb9b0b561cb@baylibre.com?part=6

  reply	other threads:[~2026-06-25 22:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 21:55 [PATCH v2 0/8] iio: adc: new ti-ads112c14 driver David Lechner
2026-06-25 21:55 ` [PATCH v2 1/8] dt-bindings: iio: adc: Add reference-sources property David Lechner
2026-06-26 16:12   ` Conor Dooley
2026-06-29  6:47   ` Kurt Borja
2026-06-25 21:55 ` [PATCH v2 2/8] dt-bindings: iio: adc: Add excitation current sources properties David Lechner
2026-06-26 16:10   ` Conor Dooley
2026-07-01 19:39   ` Jonathan Cameron
2026-07-01 22:07     ` David Lechner
2026-06-25 21:55 ` [PATCH v2 3/8] dt-bindings: iio: adc: Add burn-out current properties David Lechner
2026-06-26 16:12   ` Conor Dooley
2026-06-25 21:55 ` [PATCH v2 4/8] dt-bindings: iio: adc: add input-channel-rotation property David Lechner (TI)
2026-06-26 16:14   ` Conor Dooley
2026-06-26 18:27     ` David Lechner
2026-07-01 19:41       ` Jonathan Cameron
2026-07-02 18:58         ` Conor Dooley
2026-07-02 19:30           ` Jonathan Cameron
2026-06-25 21:55 ` [PATCH v2 5/8] dt-bindings: iio: adc: add ti,ads122c14 David Lechner (TI)
2026-06-25 22:12   ` sashiko-bot
2026-06-26 16:18   ` Conor Dooley
2026-06-26 18:35     ` David Lechner
2026-06-27 14:03       ` Conor Dooley
2026-07-01 19:50   ` Jonathan Cameron
2026-06-25 21:55 ` [PATCH v2 6/8] iio: adc: add ti-ads112c14 driver David Lechner (TI)
2026-06-25 22:07   ` sashiko-bot [this message]
2026-07-01 19:59   ` Jonathan Cameron
2026-06-25 21:55 ` [PATCH v2 7/8] iio: adc: ti-ads112c14: implement gain on internal short SYS_MON channel David Lechner (TI)
2026-06-25 22:08   ` sashiko-bot
2026-07-01 20:02   ` Jonathan Cameron
2026-06-25 21:55 ` [PATCH v2 8/8] iio: adc: ti-ads112c14: add measurement channel support David Lechner (TI)
2026-06-25 22:11   ` sashiko-bot
2026-07-01 20:20   ` Jonathan Cameron
2026-07-02  9:18     ` Andy Shevchenko
2026-07-02 14:18       ` David Lechner
2026-07-02 19:10         ` Jonathan Cameron
2026-07-03  5:55         ` 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=20260625220711.1B8F21F000E9@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 \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.