All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrei Stancovici" <andrei.stancovici@analog.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v4 2/3] iio: adc: ltc2497: add LTC2499 internal temperature channel
Date: Wed, 09 Sep 2026 08:39:49 +0000	[thread overview]
Message-ID: <20260909083950.316F11F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909082755.366269-3-andrei.stancovici@analog.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The IIO_TEMP channel scale and offset calculations omit the ADC resolution divisor, causing temperature readings to be incorrect by a factor of over 16 million.
--

commit 675eebaaf0b1a3975b7d05ae2a5dc9c63db82edc
Author: Andrei Stancovici <andrei.stancovici@analog.com>

iio: adc: ltc2497: add LTC2499 internal temperature channel
    
The LTC2499 includes an internal temperature sensor.  Expose it as an
IIO_TEMP channel with raw, scale and offset.

Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/2499fe.pdf

> diff --git a/drivers/iio/adc/ltc2497-core.c b/drivers/iio/adc/ltc2497-core.c
> index 2dc5c70442694..6df9c72bd8cf4 100644
> --- a/drivers/iio/adc/ltc2497-core.c
> +++ b/drivers/iio/adc/ltc2497-core.c
[ ... ]
> @@ -95,10 +97,45 @@ static int ltc2497core_read_raw(struct iio_dev *indio_dev,
>  		if (ret < 0)
>  			return ret;
>  
> -		*val = ret / 1000;
> -		*val2 = ddata->chip_info->resolution + 1;
> -
> -		return IIO_VAL_FRACTIONAL_LOG2;
> +		switch (chan->type) {
> +		case IIO_TEMP:
> +			/*
> +			 * raw is normalised to 2^(resolution + 1), i.e.
> +			 * raw = 2 * DATAOUT24, so the PTAT scale (datasheet
> +			 * Vref / 1570 per Kelvin) doubles its denominator and,
> +			 * in m°C, becomes Vref_uV / 3140000.
> +			 */
> +			*val = ret;
> +			*val2 = 3140000;
> +			return IIO_VAL_FRACTIONAL;

[Severity: High]
Does this scale calculation in ltc2497core_read_raw() omit the necessary
division by the ADC resolution (2^25)?

Without the resolution divisor, the temperature readings could be incorrect by
a factor of over 16 million when a userspace application reads the sysfs
attributes and applies the standard IIO formula (raw + offset) * scale.

> +		case IIO_VOLTAGE:
> +			*val = ret / (MICRO / MILLI);
> +			*val2 = ddata->chip_info->resolution + 1;
> +			return IIO_VAL_FRACTIONAL_LOG2;
> +		default:
> +			return -EINVAL;
> +		}
> +
> +	case IIO_CHAN_INFO_OFFSET:
> +		switch (chan->type) {
> +		case IIO_TEMP:
> +			ret = regulator_get_voltage(ddata->ref);
> +			if (ret < 0)
> +				return ret;
> +			if (ret == 0)
> +				return -EINVAL;
> +			/*
> +			 * 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(ABSOLUTE_ZERO_MILLICELSIUS * 3140000LL, ret);

[Severity: High]
Since this offset in ltc2497core_read_raw() is calculated based on the
potentially broken scale from above, will this result in an offset that cannot
correct for the missing resolution divisor?

> +			return IIO_VAL_INT;
> +		default:
> +			return -EINVAL;
> +		}
>  
>  	default:
>  		return -EINVAL;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909082755.366269-1-andrei.stancovici@analog.com?part=2

  reply	other threads:[~2026-09-09  8:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  8:27 [PATCH v4 0/3] iio: adc: add LTC2499 features support Andrei Stancovici
2026-09-09  8:27 ` [PATCH v4 1/3] dt-bindings: iio: adc: lltc,ltc2497: add LTC2499 to title Andrei Stancovici
2026-09-09  8:32   ` sashiko-bot
2026-09-09  8:27 ` [PATCH v4 2/3] iio: adc: ltc2497: add LTC2499 internal temperature channel Andrei Stancovici
2026-09-09  8:39   ` sashiko-bot [this message]
2026-09-09  8:27 ` [PATCH v4 3/3] iio: adc: ltc2497: add 2x conversion speed mode Andrei Stancovici
2026-09-09 14:04   ` 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=20260909083950.316F11F00A3A@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.