From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796300881; b=nzw3zNNGmHVA42jS1bzwyfue3wPqI/0kKO48IFy6ACAFmKlvzeLScG+uvdDlsQ5ODDPP 7IzAp2B5ikRh5TpjmIoiwobKYZtJ9YVyw3jitsZFM8LXtO49v/ZJjL24awevMpMtNHTPj jZuUZvslpOmylCkM/gTC2BC3ezox7fGXhuXbIKAP1pjm3CiF4H9RnfK/JxEjuXaDAjdrw 31zNrnP6tzUi9SmV/szt0fdcSWDwgLCVlKOvF7uqwxNDmp3NnFt4frfuqjV2tFRjrvGl+ pIkhTGmGdgO5ckhRfJkwSTvEryh9Jo73nVFry7d34e0xyY2Q9HNZeprMUkroPuCLmyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796300881; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=++lUyMFZhcHeUhIqKHyDNvzeCdAtxQQF4ZVVfTe5mB4=; b=GcHN+jmGgEZh6O2040ZJCe+nNqFH679Jtg0vDu5St2/6Gi0oPnlgHubE3sjYIIzBCbBe vx3CkVkzPaEjwl3d4udf+pCp88IS/MDFCQgldlYSXLYQ3LFjQjFv6atxhlGpe84ryK2Xq 3U1/DJfB+ALBDbSZEhdvzDnZEWmd5huiGLYfod+rXegJB0pR5EsMfhvORXYuX7aF5IJXJ f/YFw+Xaf6xN6IhwYUpqRWzxdYA7arUAM7KdbD82hajpfGH5E85jsvb8w9u9myeC2Cmlb MYpSSA27L8modqGKArqNcUpM4/Q8GUpDrtBCkKKUmykMtb3JAvs1GPlx3/VOQBd/u9g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TMI4uVwI; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50C55606A32D for ; Thu, 3 Dec 2026 12:28:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TMI4uVwI Received: by smtp.kernel.org (Postfix) with ESMTPSA id B21FB1F00893; Thu, 3 Dec 2026 12:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796300880; bh=++lUyMFZhcHeUhIqKHyDNvzeCdAtxQQF4ZVVfTe5mB4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=TMI4uVwIxuuaVmelUOJ7TGNdHqope/R6Qv6DWTu5nJQoLtCDy9DRPLT3RR5w0FTtH +1fPgosOhtiuIyMCRdmioBR9gIzBLhA+Z1RvkwBUQ+o5xoyVGQXc+5OdCN75Dlyt5I sHqhfpq/Z5i37Js8x2Pa0tO6I6wnNYgtilCx8DNH0XLm75Ah+QyPVKa7WNXAhWWTxj SEA+NNi9uj+Y1WKGZweY6J7SF77y0by8dnUp6GjwsaaW1Ije5ueE/iIfXqp2OkZHBU nfvDCBdv5Q07lEsWrsAnCBgTQuyMXFpXrUgijvJCN3OKx51HddTOIJ+M9NhA30D73Z Hv/sTFSNJDVOA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs Reply-To: sashiko-reviews@lists.linux.dev To: "Ben Grisdale" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261203-mt6797-thermal-support-v1-1-19595fe11814@protonmail.ch> References: <20261203-mt6797-thermal-support-v1-0-19595fe11814@protonmail.ch> <20261203-mt6797-thermal-support-v1-1-19595fe11814@protonmail.ch> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 12:28:00 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 =3D=3D 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 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/mediat= ek/thermal/mt6797/src/mtk_tc.c#L326-L659 [1] Link: https://github.com/NotKit/kernel-4.4-alps/blob/master/drivers/misc/me= diatek/thermal/mt6757/src/mtk_tc.c#L257-L570 [2] Link: https://github.com/LineageOS/android_kernel_xiaomi_mt6768/blob/lineag= e-24.0/drivers/misc/mediatek/thermal/mt6768/src/mtk_tc.c#L280-L643 [3] Link: https://github.com/LineageOS/android_kernel_xiaomi_mt6768/blob/lineag= e-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; > } > =20 > +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 =3D=3D 0) > + return 0; [Severity: Medium] Should raw =3D=3D 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 &=3D 0xfff; > + g_gain =3D 10000 + (((mt->adc_ge - 512) * 10000) >> 12); > + g_oe =3D mt->adc_oe - 512; > + format_1 =3D mt->vts[sensno] + 3350 - g_oe; > + format_2 =3D (mt->degc_cali * 10) >> 1; > + g_x_roomt =3D (((format_1 * 10000) >> 12) * 10000) / g_gain; > + > + tmp =3D (((((raw - g_oe) * 10000) >> 12) * 10000) / g_gain) - g_x_roomt; > + tmp =3D tmp * 15 / 18; > + > + if (mt->o_slope_sign =3D=3D 0) > + tmp =3D (tmp * 1000) / (mt->conf->cali_val + mt->o_slope * 10); > + else > + tmp =3D (tmp * 1000) / (mt->conf->cali_val - mt->o_slope * 10); > + > + tmp =3D 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; > } > =20 > +static int mtk_thermal_extract_efuse_v1_5(struct mtk_thermal *mt, u32 *b= uf) > +{ > + int i; > + > + if (!(buf[0] & CALIB_BUF0_VALID_V1)) > + return -EINVAL; > + > + mt->adc_ge =3D CALIB_BUF1_ADC_GE_V1(buf[1]); > + mt->adc_oe =3D CALIB_BUF1_ADC_OE_V1_5(buf[1]); > + > + for (i =3D 0; i < mt->conf->num_sensors; i++) { > + switch (mt->conf->vts_index[i]) { > + case VTS1: > + mt->vts[VTS1] =3D CALIB_BUF0_VTS_TS1_V1(buf[0]); > + break; > + case VTS2: > + mt->vts[VTS2] =3D CALIB_BUF0_VTS_TS2_V1(buf[0]); > + break; > + case VTS3: > + mt->vts[VTS3] =3D CALIB_BUF1_VTS_TS3_V1(buf[1]); > + break; > + case VTS4: > + mt->vts[VTS4] =3D CALIB_BUF2_VTS_TS4_V1(buf[2]); > + break; > + case VTS5: > + mt->vts[VTS5] =3D CALIB_BUF2_VTS_TS5_V1(buf[2]); > + break; > + case VTSABB: > + mt->vts[VTSABB] =3D > + CALIB_BUF2_VTS_TSABB_V1(buf[2]); > + break; > + default: > + break; > + } > + } > + > + mt->degc_cali =3D CALIB_BUF0_DEGC_CALI_V1(buf[0]); > + mt->o_slope_sign =3D CALIB_BUF0_O_SLOPE_SIGN_V1(buf[0]); > + if (CALIB_BUF1_ID_V1(buf[1])) > + mt->o_slope =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-mt6797-the= rmal-support-v1-0-19595fe11814@protonmail.ch?part=3D1