From: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
To: sashiko-reviews@lists.linux.dev
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 3/7] iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC
Date: Sun, 29 Nov 2026 19:41:53 +0530 [thread overview]
Message-ID: <999ee50a-92f4-4eab-8cbf-977a74204dcc@oss.qualcomm.com> (raw)
In-Reply-To: <sashiko-outbox-224862@kernel.org>
On 11/20/2026 3:05 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Medium] iio: adc: 32-bit overflow in
> qcom_adc5_gen4_scale_hw_calib_therm()
> - [Medium] iio: adc: missing DIV20 channel entries in
> adc5_gen4_chans_pmic
> --
>
...
>>
>> +static const struct adc5_channels adc5_gen4_chans_pmic[ADC5_MAX_CHANNEL] = {
>> + [ADC5_GEN4_OFFSET_REF] = ADC5_CHAN_VOLT(0, SCALE_HW_CALIB_DEFAULT)
>> + [ADC5_GEN4_1P25VREF] = ADC5_CHAN_VOLT(0, SCALE_HW_CALIB_DEFAULT)
>> + [ADC5_GEN4_VPH_PWR] = ADC5_CHAN_VOLT(1, SCALE_HW_CALIB_DEFAULT)
>> + [ADC5_GEN4_VBAT_SNS_QBG] = ADC5_CHAN_VOLT(1, SCALE_HW_CALIB_DEFAULT)
>> + [ADC5_GEN4_DIE_TEMP] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_PMIC_THERM_PM7)
>> + [ADC5_GEN4_AMUX1_THM_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX2_THM_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX3_THM_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX4_THM_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX5_THM_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX6_THM_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX1_GPIO_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX2_GPIO_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX3_GPIO_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX4_GPIO_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> + [ADC5_GEN4_AMUX5_GPIO_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
>> +};
>
> [Severity: Medium]
> Should adc5_gen4_chans_pmic[] include entries for ADC5_GEN4_USB_SNS_DIV20
> (0x11) and ADC5_GEN4_VIN_DIV20_MUX (0x12)?
>
> Both macros are added in include/linux/iio/adc/qcom-adc5-gen3-common.h
> (matching ADC5_GEN3_USB_SNS_V_16 and ADC5_GEN3_VIN_DIV16_MUX in
> adc5_gen3_chans_pmic[]), but without entries here their info_mask remains
> 0 and adc5_gen3_get_fw_channel_data() rejects those channels with -EINVAL,
> failing probe.
I'll add them in this list in the next patch version.
>
> [ ... ]
>
>> diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
>> index b03cf584b1657..5c4052f6f24fd 100644
>> --- a/drivers/iio/adc/qcom-vadc-common.c
>> +++ b/drivers/iio/adc/qcom-vadc-common.c
> [ ... ]
>> @@ -556,6 +561,31 @@ static int qcom_vadc7_scale_hw_calib_therm(
>> return 0;
>> }
>>
>> +static int qcom_adc5_gen4_scale_hw_calib_therm(
>> + const struct u32_fract *prescale,
>> + const struct adc5_data *data,
>> + u16 adc_code, int *result_mdec)
>> +{
>> + s64 resistance = adc_code;
>> + int ret, result;
>> +
>> + if (adc_code >= RATIO_MAX_ADC5_GEN4)
>> + return -EINVAL;
>> +
>> + /* (ADC code * R_PULLUP (100Kohm)) / (full_scale_code - ADC code)*/
>> + resistance *= R_PU_100K;
>> + resistance = div64_s64(resistance, RATIO_MAX_ADC5_GEN4 - adc_code);
>> +
>> + ret = qcom_vadc_map_voltage_temp(adcmap7_100k, ARRAY_SIZE(adcmap7_100k),
>> + resistance, &result);
>
> [Severity: Medium]
> Can resistance overflow the s32 input parameter of
> qcom_vadc_map_voltage_temp() when adc_code is between 0xfffc and 0xfffe?
>
I have a fix for this in hand and I'll add it in the series when I push
the next version.
Thanks,
Jishnu
> With 16-bit RATIO_MAX_ADC5_GEN4 (0xffff), adc_code values in 65532..65534
> yield a 64-bit resistance between 2,184,400,000 and 6,553,400,000, which
> exceeds S32_MAX and wraps negative when passed to
> qcom_vadc_map_voltage_temp():
>
> drivers/iio/adc/qcom-vadc-common.c:qcom_vadc_map_voltage_temp() {
> ...
> while (i < tablesize && pts[i].x > input)
> i++;
>
> if (i == 0) {
> *output = pts[0].y;
> } else if (i == tablesize) {
> *output = pts[tablesize - 1].y;
> ...
> }
>
> Because every table entry's x is positive, a wrapped negative input
> advances i to tablesize and reports the hottest temperature in the table
> (+130.048 degC) instead of the coldest (-40.960 degC) on a very cold or
> open-circuit thermistor reading, which can trigger false critical thermal
> trips.
>
next prev parent reply other threads:[~2026-11-29 14:12 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 9:19 [PATCH v2 0/7] Add support for QCOM SPMI PMIC5 Gen4 ADC Jishnu Prakash
2026-11-20 9:19 ` [PATCH v2 1/7] dt-bindings: iio: adc: Add "qcom,adc5-gen4" property for ADC channels Jishnu Prakash
2026-11-21 20:27 ` Jonathan Cameron
2026-11-29 14:11 ` Jishnu Prakash
2026-11-20 9:19 ` [PATCH v2 2/7] iio: adc: qcom-adc5-gen3: Explicitly assign enum values used in hardware Jishnu Prakash
2026-11-20 9:19 ` [PATCH v2 3/7] iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC Jishnu Prakash
2026-11-20 9:35 ` sashiko-bot
2026-11-29 14:11 ` Jishnu Prakash [this message]
2026-11-20 10:14 ` Andy Shevchenko
2026-11-21 20:29 ` Jonathan Cameron
2026-11-29 14:12 ` Jishnu Prakash
2026-11-21 20:58 ` Jonathan Cameron
2026-11-29 14:12 ` Jishnu Prakash
2026-11-20 9:19 ` [PATCH v2 4/7] thermal: qcom: qcom-spmi-adc-tm5-gen3: " Jishnu Prakash
2026-11-21 21:07 ` Jonathan Cameron
2026-11-29 14:12 ` Jishnu Prakash
2026-11-20 9:19 ` [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Remove Gen3 virtual channel macros Jishnu Prakash
2026-11-21 21:08 ` Jonathan Cameron
2026-11-20 9:19 ` [PATCH v2 6/7] dt-bindings: iio: adc: Add support for QCOM PMIC5 Gen4 ADC Jishnu Prakash
2026-11-21 21:10 ` Jonathan Cameron
2026-11-20 9:19 ` [PATCH v2 7/7] iio: adc: qcom-spmi-adc5-gen3: Add support for Gen4 ADC master PMICs Jishnu Prakash
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=999ee50a-92f4-4eab-8cbf-977a74204dcc@oss.qualcomm.com \
--to=jishnu.prakash@oss.qualcomm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox