From: sashiko-bot@kernel.org
To: "Roman Vivchar via B4 Relay" <devnull+rva333.protonmail.com@kernel.org>
Cc: krzk+dt@kernel.org, conor+dt@kernel.org, robh@kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v2 07/16] thermal: mediatek: add PMIC thermal support
Date: Wed, 13 May 2026 19:57:07 +0000 [thread overview]
Message-ID: <20260513195708.07CD0C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260512-mt6323-v2-7-3efcba579e88@protonmail.com>
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Incorrect error handling logic prevents the use of default calibration values and masks fatal hardware errors.
- [High] MT6323_TEMP_MAX is capped at 50°C, causing valid high temperatures to be discarded and breaking thermal mitigation.
- [High] Signed integer overflow in temperature calculation results in wildly negative temperatures under load.
- [High] Missing NULL check for the result of `device_get_match_data()` leads to a potential kernel panic on probe.
- [High] Missing Kconfig dependencies on the IIO subsystem.
- [Medium] NVMEM byte stream is incorrectly cast directly to a `u16` array, causing Big Endian read failures.
--
commit 7a6cbdb919c201e8e0890350ae5a7b867cecd588
Author: Roman Vivchar <rva333@protonmail.com>
thermal: mediatek: add PMIC thermal support
Add a new driver to support thermal monitoring on MediaTek PMICs, which
retrieves calibration data from EFUSE and registers with the thermal framework.
> diff --git a/drivers/thermal/mediatek/Kconfig b/drivers/thermal/mediatek/Kconfig
> index d82c86d9be563..8320d109fde68 100644
> --- a/drivers/thermal/mediatek/Kconfig
> +++ b/drivers/thermal/mediatek/Kconfig
> @@ -34,4 +34,16 @@ config MTK_LVTS_THERMAL_DEBUGFS
> help
> Enable this option to debug the internals of the device driver.
>
> +config MTK_PMIC_THERMAL
> + tristate "AUXADC temperature sensor driver for MediaTek PMICs"
> + depends on MFD_MT6397
Should this also depend on IIO?
If the thermal driver is compiled as built-in (CONFIG_MTK_PMIC_THERMAL=y)
while IIO is compiled as a module (CONFIG_IIO=m), could the kernel build
fail during linking with unresolved symbols?
> + help
> + Enable this option if you want to get PMIC temperature
[ ... ]
> diff --git a/drivers/thermal/mediatek/mtk_pmic_thermal.c b/drivers/thermal/mediatek/mtk_pmic_thermal.c
> new file mode 100644
> index 0000000000000..f644dad15fc2f
> --- /dev/null
> +++ b/drivers/thermal/mediatek/mtk_pmic_thermal.c
> @@ -0,0 +1,316 @@
[ ... ]
> +#define MAX_SENSORS 1
> +
> +#define MT6323_TEMP_MIN (-20 * MILLIDEGREE_PER_DEGREE)
> +#define MT6323_TEMP_MAX (50 * MILLIDEGREE_PER_DEGREE)
Is 50 degrees Celsius the intended maximum limit for MT6323_TEMP_MAX?
PMICs routinely operate well above 50 degrees under normal load, and thermal
mitigation trip points are typically set above 105 degrees.
Could this cap cause the driver to return -EINVAL for valid high temperatures,
effectively hiding overheating from the thermal subsystem?
[ ... ]
> +static int mtk_pmic_read_temp(struct thermal_zone_device *tz, int *temperature)
> +{
> + struct mtk_pmic_sensor *sensor = thermal_zone_device_priv(tz);
> + int ret, raw, temp;
> +
> + ret = iio_read_channel_processed(sensor->adc_channel, &raw);
> + if (ret < 0) {
> + dev_err(sensor->mt->dev, "failed to read iio channel: %d\n",
> + ret);
> + return ret;
> + }
> +
> + /*
> + * slope1 * V
> + * t = Intercept + ----------
> + * slope2
> + */
> + temp = sensor->mt->t_intercept +
> + (sensor->mt->t_slope1 * raw) / sensor->mt->t_slope2;
Can the multiplication of mt->t_slope1 and raw overflow the signed 32-bit
integer here?
mt->t_slope1 is initialized to 100,000, and raw comes from an AUXADC
with a resolution up to 32,767. Any raw value exceeding 21,474 will
cause the multiplication to exceed 2,147,483,647.
Would it be better to use a 64-bit cast, such as div_s64(), to avoid
returning wrapped negative temperatures when the device is under load?
> +
> + if (!mtk_pmic_thermal_temp_is_valid(temp))
> + return -EINVAL;
> +
> + *temperature = temp;
> + return 0;
> +}
[ ... ]
> +static int mtk_pmic_thermal_extract_efuse_mt6323(struct mtk_pmic_thermal *mt,
> + u16 *buf)
> +{
> + u32 reg;
> + s32 vts, degc_cali, o_slope, o_slope_sign, id;
> + int ret;
> +
> + if (!FIELD_GET(CALIB_BUF0_ADC_CALI_EN_MASK, buf[0]))
Does buf need to be parsed with endian-safe helpers?
Since nvmem_cell_read() returns an opaque byte stream buffer, treating it
directly as a u16 array relies on the CPU byte order. On a big-endian kernel,
could this swap the bytes within each 16-bit word and corrupt the
calibration data?
> + return -EINVAL;
> +
> + /* Voltage offset */
[ ... ]
> +static int mtk_pmic_thermal_get_calib_data(struct device *dev,
> + struct mtk_pmic_thermal *mt)
> +{
> + void *buf __free(kfree) = NULL;
> + struct nvmem_cell *cell;
> + size_t len;
> + int ret;
> +
> + cell = nvmem_cell_get(dev, NULL);
> + if (IS_ERR(cell))
> + return PTR_ERR(cell);
Does returning here bypass the fallback logic for uncalibrated devices?
If nvmem_cell_get() returns -ENOENT because the nvmem-cells property is
legitimately missing from the device tree, the probe is aborted before
applying the default calibration values.
> +
> + buf = nvmem_cell_read(cell, &len);
> + nvmem_cell_put(cell);
> +
> + if (IS_ERR(buf)) {
> + ret = PTR_ERR(buf);
> + buf = NULL;
> + return ret;
> + }
> +
> + if (len < 2 * sizeof(u16)) {
> + dev_err(dev, "invalid calibration data length\n");
> + return -EINVAL;
> + }
> +
> + ret = mt->data->extract_efuse(mt, buf);
> + if (ret) {
> + dev_info(dev, "device not calibrated, using default values\n");
Conversely, if extract_efuse() encounters a hardware communication error
or an invalid chip ID, will this incorrectly mask the hardware error as
"device not calibrated"?
This might cause the driver to register the thermal zone using default values
on unresponsive hardware.
> + mt->data->precalc(mt, MT6323_DEFAULT_VTS,
> + MT6323_DEFAULT_DEGC_CALI,
> + MT6323_DEFAULT_SLOPE,
> + MT6323_DEFAULT_SLOPE_SIGN);
> + }
> +
> + return 0;
> +}
[ ... ]
> +static int mtk_pmic_thermal_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct mtk_pmic_thermal *mt;
> + int ret;
> +
> + mt = devm_kzalloc(dev, sizeof(*mt), GFP_KERNEL);
> + if (!mt)
> + return -ENOMEM;
> +
> + mt->regmap = dev_get_regmap(dev->parent->parent, NULL);
> + if (!mt->regmap)
> + return dev_err_probe(dev, -ENODEV, "failed to get regmap");
> +
> + mt->dev = dev;
> + mt->data = device_get_match_data(dev);
Should mt->data be checked for NULL?
If the driver is bound to the MFD cell purely by platform name (e.g., if
the MFD core does not pass an of_node to the cell), device_get_match_data()
will return NULL.
> +
> + ret = mtk_pmic_thermal_get_calib_data(dev, mt);
If mt->data is NULL, calling mtk_pmic_thermal_get_calib_data() will
dereference a NULL pointer when it attempts to call
mt->data->extract_efuse(mt, buf).
> + if (ret)
> + return ret;
> +
> + for (int i = 0; i < mt->data->num_sensors; i++) {
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260512-mt6323-v2-0-3efcba579e88@protonmail.com?part=7
next prev parent reply other threads:[~2026-05-13 19:57 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 5:18 [PATCH v2 00/16] add AUXADC, EFUSE and thermal drivers for the MediaTek mt6323 PMIC Roman Vivchar via B4 Relay
2026-05-12 5:18 ` [PATCH v2 01/16] dt-bindings: iio: adc: mt6359: generalize description for mt63xx series Roman Vivchar via B4 Relay
2026-05-12 13:13 ` Jonathan Cameron
2026-05-12 13:55 ` Roman Vivchar
2026-05-12 17:06 ` Jonathan Cameron
2026-05-12 5:18 ` [PATCH v2 02/16] dt-bindings: iio: adc: mt6359: add mt6323 PMIC AUXADC Roman Vivchar via B4 Relay
2026-05-12 5:18 ` [PATCH v2 03/16] dt-bindings: mfd: mediatek: mt6397: add mt6323 PMIC EFUSE Roman Vivchar via B4 Relay
2026-05-13 4:44 ` sashiko-bot
2026-05-12 5:18 ` [PATCH v2 04/16] dt-bindings: mfd: mediatek: mt6397: add mt6323 PMIC thermal Roman Vivchar via B4 Relay
2026-05-13 5:00 ` sashiko-bot
2026-05-12 5:18 ` [PATCH v2 05/16] iio: adc: mediatek: add mt6323 PMIC AUXADC driver Roman Vivchar via B4 Relay
2026-05-12 6:43 ` Andy Shevchenko
2026-05-12 13:29 ` Jonathan Cameron
2026-05-12 14:34 ` Roman Vivchar
2026-05-12 16:56 ` Andy Shevchenko
2026-05-12 17:04 ` Jonathan Cameron
2026-05-13 5:46 ` sashiko-bot
2026-05-12 5:18 ` [PATCH v2 06/16] nvmem: add mt6323 PMIC EFUSE driver Roman Vivchar via B4 Relay
2026-05-12 6:47 ` Andy Shevchenko
2026-05-13 19:24 ` sashiko-bot
2026-05-12 5:18 ` [PATCH v2 07/16] thermal: mediatek: add PMIC thermal support Roman Vivchar via B4 Relay
2026-05-12 7:04 ` Andy Shevchenko
2026-05-12 8:55 ` Roman Vivchar
2026-05-12 11:02 ` Andy Shevchenko
2026-05-12 13:33 ` Jonathan Cameron
2026-05-13 19:57 ` sashiko-bot [this message]
2026-05-12 5:18 ` [PATCH v2 08/16] mfd: mt6397-core: add mt6323 AUXADC support Roman Vivchar via B4 Relay
2026-05-12 5:18 ` [PATCH v2 09/16] mfd: mt6397-core: add mt6323 EFUSE support Roman Vivchar via B4 Relay
2026-05-12 5:18 ` [PATCH v2 10/16] mfd: mt6397-core: add mt6323 thermal support Roman Vivchar via B4 Relay
2026-05-12 7:07 ` Andy Shevchenko
2026-05-13 20:24 ` sashiko-bot
2026-05-12 5:18 ` [PATCH v2 11/16] ARM: dts: mediatek: mt6323: add AUXADC support Roman Vivchar via B4 Relay
2026-05-12 5:18 ` [PATCH v2 12/16] ARM: dts: mediatek: mt6323: add EFUSE support Roman Vivchar via B4 Relay
2026-05-12 5:18 ` [PATCH v2 13/16] ARM: dts: mediatek: mt6323: add thermal support Roman Vivchar via B4 Relay
2026-05-13 20:58 ` sashiko-bot
2026-05-12 5:18 ` [PATCH v2 14/16] MAINTAINERS: add MediaTek mt6323 PMIC AUXADC driver maintainer Roman Vivchar via B4 Relay
2026-05-12 13:36 ` Jonathan Cameron
2026-05-12 5:18 ` [PATCH v2 15/16] MAINTAINERS: add MediaTek mt6323 PMIC EFUSE " Roman Vivchar via B4 Relay
2026-05-12 5:18 ` [PATCH v2 16/16] MAINTAINERS: add MediaTek mt6323 PMIC thermal " Roman Vivchar via B4 Relay
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=20260513195708.07CD0C19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=devnull+rva333.protonmail.com@kernel.org \
--cc=krzk+dt@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