From: sashiko-bot@kernel.org
To: "Ben Grisdale" <bengris32@protonmail.ch>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs
Date: Thu, 03 Dec 2026 12:28:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-247723@kernel.org> (raw)
In-Reply-To: <20261203-mt6797-thermal-support-v1-1-19595fe11814@protonmail.ch>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] thermal: mediatek: negative signed left shift in
raw_to_mcelsius_v1_5()
- [Medium] thermal: mediatek: raw == 0 returns 0 mC in
raw_to_mcelsius_v1_5()
- [Low] thermal: mediatek: duplicated efuse logic in
mtk_thermal_extract_efuse_v1_5()
--
commit c3dd11d0a97055e44df1e363ad510a84e28f5420
Author: Ben Grisdale <bengris32@protonmail.ch>
thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs
This commit adds MTK_THERMAL_V1_5 support to the MediaTek AUXADC thermal
driver for mobile SoCs, including efuse calibration extraction with
ADC_OE and a corresponding raw-to-millicelsius conversion helper.
Link: https://github.com/helio-x20/linux/blob/helio-x20/drivers/misc/mediatek/thermal/mt6797/src/mtk_tc.c#L326-L659 [1]
Link: https://github.com/NotKit/kernel-4.4-alps/blob/master/drivers/misc/mediatek/thermal/mt6757/src/mtk_tc.c#L257-L570 [2]
Link: https://github.com/LineageOS/android_kernel_xiaomi_mt6768/blob/lineage-24.0/drivers/misc/mediatek/thermal/mt6768/src/mtk_tc.c#L280-L643 [3]
Link: https://github.com/LineageOS/android_kernel_xiaomi_mt6768/blob/lineage-24.0/drivers/misc/mediatek/thermal/mt6873/src/mtk_tc.c#L212-L584 [4]
> diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
> index 434f856c0f045..5b116cbb0af95 100644
> --- a/drivers/thermal/mediatek/auxadc_thermal.c
> +++ b/drivers/thermal/mediatek/auxadc_thermal.c
[ ... ]
> @@ -724,6 +731,37 @@ static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw)
> return mt->degc_cali * 500 - tmp;
> }
>
> +static int raw_to_mcelsius_v1_5(struct mtk_thermal *mt, int sensno, s32 raw)
> +{
> + s32 format_1;
> + s32 format_2;
> + s32 g_oe;
> + s32 g_gain;
> + s32 g_x_roomt;
> + s32 tmp;
> +
> + if (raw == 0)
> + return 0;
[Severity: Medium]
Should raw == 0 return THERMAL_TEMP_INVALID here instead of 0?
Before the first AUXADC conversion completes after controller init, the
TEMP_MSR register can read 0. Since mtk_thermal_temp_is_valid() accepts
[-20000, 150000], returning 0 passes validation and reports a bogus 0 C
temperature instead of THERMAL_TEMP_INVALID.
> +
> + raw &= 0xfff;
> + g_gain = 10000 + (((mt->adc_ge - 512) * 10000) >> 12);
> + g_oe = mt->adc_oe - 512;
> + format_1 = mt->vts[sensno] + 3350 - g_oe;
> + format_2 = (mt->degc_cali * 10) >> 1;
> + g_x_roomt = (((format_1 * 10000) >> 12) * 10000) / g_gain;
> +
> + tmp = (((((raw - g_oe) * 10000) >> 12) * 10000) / g_gain) - g_x_roomt;
> + tmp = tmp * 15 / 18;
> +
> + if (mt->o_slope_sign == 0)
> + tmp = (tmp * 1000) / (mt->conf->cali_val + mt->o_slope * 10);
> + else
> + tmp = (tmp * 1000) / (mt->conf->cali_val - mt->o_slope * 10);
> +
> + tmp = tmp - (tmp << 1);
> + return (format_2 + tmp) * 100;
> +}
[Severity: Medium]
Can tmp << 1 left-shift a negative signed s32 here?
Because raw decreases as temperature rises, tmp is negative on every
reading above degc_cali / 2 (around 20 C with defaults). Left-shifting a
negative signed integer is C11 undefined behavior and triggers
CONFIG_UBSAN_SHIFT splats (or a trap under CONFIG_UBSAN_TRAP).
Returning (format_2 - tmp) * 100, as raw_to_mcelsius_v2() does, avoids
the shift.
[ ... ]
> @@ -1034,6 +1073,50 @@ static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf)
> return 0;
> }
>
> +static int mtk_thermal_extract_efuse_v1_5(struct mtk_thermal *mt, u32 *buf)
> +{
> + int i;
> +
> + if (!(buf[0] & CALIB_BUF0_VALID_V1))
> + return -EINVAL;
> +
> + mt->adc_ge = CALIB_BUF1_ADC_GE_V1(buf[1]);
> + mt->adc_oe = CALIB_BUF1_ADC_OE_V1_5(buf[1]);
> +
> + for (i = 0; i < mt->conf->num_sensors; i++) {
> + switch (mt->conf->vts_index[i]) {
> + case VTS1:
> + mt->vts[VTS1] = CALIB_BUF0_VTS_TS1_V1(buf[0]);
> + break;
> + case VTS2:
> + mt->vts[VTS2] = CALIB_BUF0_VTS_TS2_V1(buf[0]);
> + break;
> + case VTS3:
> + mt->vts[VTS3] = CALIB_BUF1_VTS_TS3_V1(buf[1]);
> + break;
> + case VTS4:
> + mt->vts[VTS4] = CALIB_BUF2_VTS_TS4_V1(buf[2]);
> + break;
> + case VTS5:
> + mt->vts[VTS5] = CALIB_BUF2_VTS_TS5_V1(buf[2]);
> + break;
> + case VTSABB:
> + mt->vts[VTSABB] =
> + CALIB_BUF2_VTS_TSABB_V1(buf[2]);
> + break;
> + default:
> + break;
> + }
> + }
> +
> + mt->degc_cali = CALIB_BUF0_DEGC_CALI_V1(buf[0]);
> + mt->o_slope_sign = CALIB_BUF0_O_SLOPE_SIGN_V1(buf[0]);
> + if (CALIB_BUF1_ID_V1(buf[1]))
> + mt->o_slope = CALIB_BUF0_O_SLOPE_V1(buf[0]);
> +
> + return 0;
> +}
[Severity: Low]
Could this share the common efuse decoding with
mtk_thermal_extract_efuse_v1()?
The validity check, adc_ge, degc_cali, and the VTS extraction loop are
identical between V1 and V1_5, differing only in adc_oe and o_slope
handling. Sharing the common decoding or branching on mt->conf->version
in mtk_thermal_extract_efuse_v1() would avoid maintaining two copies.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-mt6797-thermal-support-v1-0-19595fe11814@protonmail.ch?part=1
next prev parent reply other threads:[~2026-12-03 12:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 12:03 [PATCH 0/4] thermal/drivers/mediatek: Sampling mode, mobile calibration & MT6797 support Ben Grisdale via B4 Relay
2026-12-03 12:03 ` Ben Grisdale
2026-12-03 12:03 ` [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs Ben Grisdale via B4 Relay
2026-12-03 12:03 ` Ben Grisdale
2026-12-03 12:28 ` sashiko-bot [this message]
2026-12-04 11:46 ` Roman Vivchar
2026-12-03 12:03 ` [PATCH 2/4] thermal/drivers/mediatek: Add support for setting sampling mode per SoC Ben Grisdale via B4 Relay
2026-12-03 12:03 ` Ben Grisdale
2026-12-04 11:50 ` Roman Vivchar
2026-12-03 12:03 ` [PATCH 3/4] dt-bindings: thermal: mediatek,thermal: Add MT6797 Ben Grisdale via B4 Relay
2026-12-03 12:03 ` Ben Grisdale
2026-12-03 12:03 ` [PATCH 4/4] thermal/drivers/mediatek: Add MT6797 support Ben Grisdale via B4 Relay
2026-12-03 12:03 ` Ben Grisdale
2026-12-03 12:53 ` sashiko-bot
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-247723@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bengris32@protonmail.ch \
--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.