From: sashiko-bot@kernel.org
To: "Andrei Stancovici" <andrei.stancovici@analog.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 2/3] iio: adc: ltc2497: add LTC2499 internal temperature channel
Date: Wed, 05 Aug 2026 09:57:22 +0000 [thread overview]
Message-ID: <20260805095723.0ACCD1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260805094135.11762-3-andrei.stancovici@analog.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Potential division by zero kernel panic if regulator_get_voltage() returns 0 when reading the temperature offset.
- [High] Stack-allocated buffer passed to i2c_master_send() is not DMA-safe.
- [High] The 2-byte command inadvertently configures 50Hz-only rejection, breaking 60Hz rejection and causing a hardcoded 150ms conversion delay to time out.
--
--- Patch [2]: [PATCH 2/3] iio: adc: ltc2497: add LTC2499 internal temperature channel ---
commit 20bcf3fffe757278d79cfcae060ca4eaa317443e
Author: Andrei Stancovici <andrei.stancovici@analog.com>
iio: adc: ltc2497: add LTC2499 internal temperature channel
This commit adds support for the LTC2499's internal PTAT temperature sensor.
It exposes the sensor as an IIO_TEMP channel, utilizing a second I2C
configuration byte to enable temperature conversions and calculate the exact
temperature using the reference voltage.
> diff --git a/drivers/iio/adc/ltc2497-core.c b/drivers/iio/adc/ltc2497-core.c
> index 2dc5c70442694..4ca7271ca0071 100644
> --- a/drivers/iio/adc/ltc2497-core.c
> +++ b/drivers/iio/adc/ltc2497-core.c
[ ... ]
> @@ -95,10 +96,43 @@ static int ltc2497core_read_raw(struct iio_dev *indio_dev,
[ ... ]
> + case IIO_CHAN_INFO_OFFSET:
> + switch (chan->type) {
> + case IIO_TEMP:
> + ret = regulator_get_voltage(ddata->ref);
> + if (ret < 0)
> + return ret;
> + /*
> + * 0 °C == 273.15 K must map to raw + offset such that
> + * (raw + offset) * scale == 0 m°C, i.e.
> + * offset = -273150 / scale
> + * = -273150 * 3140000 / Vref_uV
> + * Computed in 64-bit to avoid overflow.
> + */
> + *val = div_s64(-273150LL * 3140000, ret);
[Severity: High]
If regulator_get_voltage() returns exactly 0 (for instance, via a dummy
regulator or misconfigured devicetree), will this trigger a divide-by-zero
panic?
The check above handles negative error codes but appears to miss a
check for zero before the division.
> + return IIO_VAL_INT;
> + default:
> + return -EINVAL;
> + }
>
> default:
> return -EINVAL;
[ ... ]
> diff --git a/drivers/iio/adc/ltc2497.c b/drivers/iio/adc/ltc2497.c
> index eb9d521e86e54..4e0f5c7671f41 100644
> --- a/drivers/iio/adc/ltc2497.c
> +++ b/drivers/iio/adc/ltc2497.c
[ ... ]
> @@ -85,6 +85,36 @@ static int ltc2497_result_and_measure(struct ltc2497core_driverdata *ddata,
[ ... ]
> + if (ddata->chip_info->has_temp) {
> + u8 cmd[2];
[Severity: High]
Is this stack-allocated buffer safe to use with i2c_master_send()?
If the underlying I2C adapter driver uses DMA for transfers, it might attempt
to map this stack memory. With CONFIG_VMAP_STACK enabled, stack memory is
allocated in vmalloc space and is not DMA-capable, which could lead to
memory corruption or mapping errors.
Should this use a DMA-safe buffer instead?
> +
> + if (address == LTC2497_TEMP_ADDR) {
> + cmd[0] = LTC2497_ENABLE | LTC2497_CONFIG_DEFAULT;
> + cmd[1] = LTC2499_EN2 | LTC2499_IM;
> + } else {
> + cmd[0] = LTC2497_ENABLE | address;
> + cmd[1] = LTC2499_EN2;
> + }
[Severity: High]
By omitting bits 5 (FA) and 4 (FB) in the second command byte, these
bits default to 0. According to the LTC2499 datasheet, does this inadvertently
configure the part for 50Hz-only noise rejection?
If so, 50Hz-only mode increases the maximum conversion time to 160.3ms.
Since the driver hardcodes the wait time to 150ms via
LTC2497_CONVERSION_TIME_MS, could this result in the I2C read transaction
being NACKed by the busy ADC, causing persistent read failures?
Would explicitly setting the FA bit to maintain the 149.9ms simultaneous
50/60Hz rejection mode prevent this timeout?
> +
> + ret = i2c_master_send(st->client, cmd, sizeof(cmd));
> + if (ret < 0) {
> + dev_err(&st->client->dev, "i2c transfer failed: %pe\n",
> + ERR_PTR(ret));
> + return ret;
> + }
> + return 0;
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805094135.11762-1-andrei.stancovici@analog.com?part=2
next prev parent reply other threads:[~2026-08-05 9:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 9:41 [PATCH 0/3] iio: adc: add LTC2499 features support Andrei Stancovici
2026-08-05 9:41 ` [PATCH 1/3] dt-bindings: iio: adc: lltc,ltc2497: add LTC2499 to title Andrei Stancovici
2026-08-12 1:50 ` Rob Herring (Arm)
2026-08-05 9:41 ` [PATCH 2/3] iio: adc: ltc2497: add LTC2499 internal temperature channel Andrei Stancovici
2026-08-05 9:57 ` sashiko-bot [this message]
2026-08-05 10:00 ` Andy Shevchenko
2026-08-05 9:41 ` [PATCH 3/3] iio: adc: ltc2497: add 2x conversion speed mode Andrei Stancovici
2026-08-05 9:56 ` sashiko-bot
2026-08-05 10:08 ` 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=20260805095723.0ACCD1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=andrei.stancovici@analog.com \
--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.