From: sashiko-bot@kernel.org
To: "Mikhail Kalashnikov" <iuncuim@gmail.com>
Cc: devicetree@vger.kernel.org, linux-sunxi@lists.linux.dev,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v7 4/5] thermal/drivers/sun8i: Add support for A523 THS0/1 controllers
Date: Fri, 04 Dec 2026 11:02:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-249648@kernel.org> (raw)
In-Reply-To: <0ffd22347841e102ba4cc9e806894c7e714a4ec8.1796378254.git.iuncuim@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] thermal: sun8i: wrong bitfield check in
sun55i_a523_ths_calibrate()
- [Medium] thermal/sun8i: missing zero check in
sun55i_a523_ths_calibrate()
- [Low] thermal/sun8i: sun8i_ths_calibrate() skips devm_kfree() on 2nd
cell error
- [Low] thermal/sun8i: sun55i_a523_ths_calibrate() ignores high-temp
scale
--
commit 30ae4ac56f828a8fbb1c02d0d42f417911331818
Author: Mikhail Kalashnikov <iuncuim@gmail.com>
thermal/drivers/sun8i: Add support for A523 THS0/1 controllers
This commit adds temperature calculation, eFuse calibration, and compatible
entries for the Allwinner A523 THS0 and THS1 thermal controllers.
> diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
> index 3606548801f02..4a81486f8faec 100644
> --- a/drivers/thermal/sun8i_thermal.c
> +++ b/drivers/thermal/sun8i_thermal.c
[ ... ]
> @@ -298,6 +319,105 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev,
> return 0;
> }
>
> +/*
> + * The A523 calibration data is stored in the eFuse, split across two
> + * nvmem cells. THS1 has four sensors, including ths1_3 which is used
> + * for the NPU, each with its own calibration value. The fields are
> + * packed as shown in the layouts below.
> + *
> + * efuse layout 0x38-0x3F (caldata[0..3]):
> + * caldata[0] caldata[1] caldata[2] caldata[3]
> + * 0 16 24 32 36 48 60 64
> + * +---------------+---------------+---------------+---------------+
> + * | | | temp | ths1_0 | ths1_1 | +
> + * +---------------+---------------+---------------+---------------+
> + *
> + * efuse layout 0x44-0x4B (caldata[4..7]):
> + * caldata[4] caldata[5] caldata[6] caldata[7]
> + * 0 12 16 24 32 36 48 64
> + * +---------------+---------------+---------------+---------------+
> + * | ths1_2 | ths1_3 | ths0 | | +
> + * +---------------+---------------+---------------+---------------+
> + */
> +static int sun55i_a523_ths_calibrate(struct ths_device *tmdev,
> + u16 *caldata, int callen)
> +{
> + struct device *dev = tmdev->dev;
> + int i, ft_temp;
> +
> + if (!caldata[1])
> + return -EINVAL;
> +
> + ft_temp = (((caldata[2] << 8) | (caldata[1] >> 8)) & FT_TEMP_MASK) * 100;
[Severity: Medium]
Should this check ft_temp instead of caldata[1]?
Per the layout comment above, caldata[1] covers bits 16..31, combining
unrelated eFuse byte 0x3a with only the low 8 bits of the 12-bit factory
temperature field (bits 24..35). When byte 0x3a is 0, a valid 25.6 C
(0x100) factory calibration has caldata[1] == 0 and is rejected, silently
leaving all sensors uncalibrated at default 0x800.
Conversely, on an unprogrammed eFuse where byte 0x3a is non-zero,
caldata[1] is non-zero and calibration proceeds with ft_temp == 0.
Computing ft_temp first and checking if (!ft_temp) avoids both cases.
[ ... ]
> + sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg);
> +
> + /*
> + * Calibration data is CALIBRATE_DEFAULT - (calculated
> + * temperature from sensor reading at factory temperature
> + * minus actual factory temperature) * X (scale from
> + * temperature to register values).
> + *
> + * The BSP's SUN55IW3_CAL_COM(5000) is applied as ft_deviation
> + * in sun8i_ths_get_temp(), after calc_temp(), and therefore
> + * intentionally not repeated here.
> + */
> + cdata = CALIBRATE_DEFAULT -
> + ((sensor_temp - ft_temp) / SUN55I_A523_SCALE_BELOW);
[Severity: Low]
Can this divide by the wrong scale when sensor_reg is below
SUN55I_A523_DELIMITER (0x7c8, ~55 C)?
sun55i_a523_calc_temp() uses SUN55I_A523_SCALE_ABOVE (65) when reg is
below SUN55I_A523_DELIMITER, but this always divides by
SUN55I_A523_SCALE_BELOW (74). If factory calibration happens above
~55 C, the computed calibration offset is under-corrected by ~12.2%.
> +
> + if (cdata & ~TEMP_CALIB_MASK) {
[Severity: Medium]
Does missing a zero check on sensor_reg allow an unprogrammed sensor slot
to bypass the 12-bit range check?
If sensor_reg is 0 (for example, on an A523 variant with only 3 calibrated
THS1 sensors), sun55i_a523_calc_temp() takes the reg < SUN55I_A523_DELIMITER
branch and returns 65 * 2825 = 183625 mC. Because cdata then divides by
SUN55I_A523_SCALE_BELOW (74), any ft_temp >= 32.0 C yields cdata in
[0, 4095], passing this check and overwriting the hardware default 0x800
with a near-zero value that shifts readings by ~130-152 C and can trigger
thermal shutdown.
Checking if (!sensor_reg) and skipping calibration before calling
calc_temp() avoids corrupting SUN50I_H6_THS_TEMP_CALIB.
[ ... ]
> @@ -729,6 +874,8 @@ static const struct of_device_id of_ths_match[] = {
> { .compatible = "allwinner,sun50i-h6-ths", .data = &sun50i_h6_ths },
> { .compatible = "allwinner,sun20i-d1-ths", .data = &sun20i_d1_ths },
> { .compatible = "allwinner,sun50i-h616-ths", .data = &sun50i_h616_ths },
> + { .compatible = "allwinner,sun55i-a523-ths0", .data = &sun55i_a523_ths0 },
> + { .compatible = "allwinner,sun55i-a523-ths1", .data = &sun55i_a523_ths1 },
> { /* sentinel */ },
> };
[Severity: Low]
Now that these two-cell compatibles exercise the multi-cell path added in
commit "thermal/drivers/sun8i: get calibration data from two nvmem cells",
can sun8i_ths_calibrate() keep the temporary caldata buffer pinned on
devres until unbind?
drivers/thermal/sun8i_thermal.c:sun8i_ths_calibrate() {
...
calcell = of_nvmem_cell_get(np, cellname);
if (IS_ERR(calcell)) {
if (PTR_ERR(calcell) == -EPROBE_DEFER)
return -EPROBE_DEFER;
goto out;
}
...
devm_kfree(dev, caldata);
caldata = NULL;
out:
if (!IS_ERR_OR_NULL(calcell))
nvmem_cell_put(calcell);
return ret;
}
If of_nvmem_cell_get() fails on the second cell with a non-EPROBE_DEFER
error (such as -ENOENT on an incomplete DT), it jumps to out with ret == 0,
skipping devm_kfree(dev, caldata) while probe succeeds. Moving
devm_kfree(dev, caldata) below the out label releases it on all exit paths.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796378254.git.iuncuim@gmail.com?part=4
next prev parent reply other threads:[~2026-12-04 11:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:43 [PATCH v7 0/5] Allwinner: A523: add support for A523 THS0/1 controllers Mikhail Kalashnikov
2026-12-04 10:43 ` [PATCH v7 1/5] dt-bindings: thermal: sun8i: Add " Mikhail Kalashnikov
2026-12-04 10:43 ` [PATCH v7 2/5] thermal/drivers/sun8i: replace devm_reset_control_get to devm_reset_control_get_shared_deasserted Mikhail Kalashnikov
2026-12-04 10:43 ` [PATCH v7 3/5] thermal/drivers/sun8i: get calibration data from two nvmem cells Mikhail Kalashnikov
2026-12-04 10:58 ` sashiko-bot
2026-12-04 10:43 ` [PATCH v7 4/5] thermal/drivers/sun8i: Add support for A523 THS0/1 controllers Mikhail Kalashnikov
2026-12-04 11:02 ` sashiko-bot [this message]
2026-12-04 10:43 ` [PATCH v7 5/5] arm64: dts: allwinner: sun55i: add thermal sensors Mikhail Kalashnikov
2026-12-04 11:02 ` 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-249648@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=iuncuim@gmail.com \
--cc=linux-sunxi@lists.linux.dev \
--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