From: sashiko-bot@kernel.org
To: "Xianwei Zhao" <xianwei.zhao@amlogic.com>
Cc: linux-amlogic@lists.infradead.org, neil.armstrong@linaro.org,
robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 2/2] thermal: amlogic: Add support for A9 thermal controller
Date: Thu, 30 Jul 2026 08:46:43 +0000 [thread overview]
Message-ID: <20260730084644.44D571F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260730-a9-thermal-v1-2-d786d37cba58@amlogic.com>
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
New issues:
- [High] Double disable of 'sysclk' due to manual disable of devm-managed clock in remove callback.
- [High] Peripheral hardware registers are accessed via MMIO before their backing clocks are enabled.
- [High] Incorrect hardware reset temperature calculation for negative calibration trims due to flawed bitwise masking.
- [High] A9-specific hardware over-temperature reset configuration is applied unconditionally to all legacy SoCs.
- [High] The return value of `clk_prepare_enable(data->sysclk)` is ignored in the resume path.
- [High] An unvalidated device tree property can cause a divide-by-zero kernel panic during probe.
- [Medium] Possible truncation of `temp_code` during hardware reset configuration due to out-of-bounds bitwise masking.
Pre-existing issues:
- [High] The thermal zone is registered and unregistered in an unsafe order relative to hardware clock state.
--
--- Patch [2]: [PATCH 2/2] thermal: amlogic: Add support for A9 thermal controller ---
commit 0d417d06a989692f70ed92067eec1c72408bd3da
Author: Xianwei Zhao <xianwei.zhao@amlogic.com>
thermal: amlogic: Add support for A9 thermal controller
Add support for the Amlogic A9 thermal controller, utilizing different
calibration parameters, separate core and bus clocks, and a hardware
over-temperature reset mechanism. The hardware reset configuration is
also restored after resume.
> diff --git a/drivers/thermal/amlogic_thermal.c b/drivers/thermal/amlogic_thermal.c
> index a0b530624b60c..c9c3514966533 100644
> --- a/drivers/thermal/amlogic_thermal.c
> +++ b/drivers/thermal/amlogic_thermal.c
[ ... ]
> @@ -138,6 +154,46 @@ static int amlogic_thermal_code_to_millicelsius(struct amlogic_thermal *pdata,
> return temp;
> }
>
> +/*
> + * Calculate a temperature code from a temperature value .
> + * The unit of the temperature is degree milliCelsius.
> + */
> +static u32 amlogic_thermal_millicelsius_to_code(struct amlogic_thermal *pdata, int millicelsius)
> +{
> + const struct amlogic_thermal_soc_calib_data *param =
> + pdata->data->calibration_parameters;
> + s64 factor, uptat, uefuse;
> + u32 temp_code;
> +
> + uefuse = pdata->trim_info & TSENSOR_TRIM_SIGN_MASK ?
> + ~(pdata->trim_info & TSENSOR_TRIM_TEMP_MASK) + 1 :
> + (pdata->trim_info & TSENSOR_TRIM_TEMP_MASK);
> +
> + factor = param->B + div_s64(millicelsius, 100);
> + factor = BIT(16) * factor;
> + factor = div_s64(factor, param->A);
> + factor = factor - (uefuse & TSENSOR_TRIM_TEMP_MASK);
[Severity: High]
Does this bitwise mask strip the negative sign extension?
The uefuse variable can hold a negative calibration trim, but applying
TSENSOR_TRIM_TEMP_MASK here seems to destroy the negative offset, which
could cause extreme positive values and corrupt the reset temperature logic.
> +
> + uptat = param->n * factor;
> + uptat = div_s64(uptat, BIT(16));
> + uptat = param->m - uptat;
> +
> + factor = factor * 100;
> + factor = div_s64(factor, uptat);
[Severity: High]
Is there a risk of a divide-by-zero kernel panic here?
If the 'amlogic,hw-reset-temp' device tree property is set to a value around
981,000 mC, it looks like uptat can evaluate to zero. Should we validate the
reset temperature bounds before using it as a divisor?
> +
> + temp_code = ((factor >> 0x4) & TSENSOR_TEMP_MASK) + TSENSOR_TEMP_CAL;
[Severity: Medium]
Could this bitwise mask truncate valid temperature codes?
If temp_code evaluates to 13 bits, it would exceed the 12-bit bounds of
TSENSOR_TEMP_MASK. This might lead to a zeroed reset configuration at high
temperatures.
> +
> + return temp_code;
> +}
[ ... ]
> @@ -323,9 +398,24 @@ static int amlogic_thermal_probe(struct platform_device *pdev)
[ ... ]
> pdata->tzd = devm_thermal_of_zone_register(&pdev->dev,
> 0,
> pdata,
> &amlogic_thermal_ops);
[Severity: High]
This isn't a bug introduced by this patch, but does registering the thermal
zone here expose it prematurely?
Using devm_thermal_of_zone_register() before clocks are fully enabled allows
the core to poll the device immediately, which could cause a bus hang on
unclocked hardware access. Cleanup will also happen after clocks are disabled.
> if (IS_ERR(pdata->tzd)) {
> ret = PTR_ERR(pdata->tzd);
> dev_err(dev, "Failed to register tsensor: %d\n", ret);
> return ret;
> }
>
> devm_thermal_add_hwmon_sysfs(&pdev->dev, pdata->tzd);
>
> + pdata->temp_code = amlogic_thermal_millicelsius_to_code(pdata, reset_temp);
> +
> + amlogic_tsensor_setup_hw_reset(pdata);
[Severity: High]
Does this unconditionally apply A9-specific hardware over-temperature
configuration to all legacy SoCs?
Since this function writes to TSENSOR_CFG_REG2, which appears to be
A9-specific, applying it across all platforms without checking the SoC type
might cause undefined behavior on legacy hardware.
> +
> ret = amlogic_thermal_enable(pdata);
[ ... ]
> @@ -355,6 +449,8 @@ static void amlogic_thermal_remove(struct platform_device *pdev)
> {
> struct amlogic_thermal *data = platform_get_drvdata(pdev);
>
> + if (data->data->has_sysclk)
> + clk_disable_unprepare(data->sysclk);
[Severity: High]
Can this cause a reference count underflow for sysclk?
The sysclk was acquired in amlogic_thermal_probe() using
devm_clk_get_enabled(). Manually disabling a devm-managed clock here in the
remove callback could cause a double disable when the devm cleanup runs.
> amlogic_thermal_disable(data);
> }
[ ... ]
> @@ -371,6 +469,9 @@ static int amlogic_thermal_resume(struct device *dev)
> {
> struct amlogic_thermal *data = dev_get_drvdata(dev);
>
> + amlogic_tsensor_setup_hw_reset(data);
[Severity: High]
Will this cause a bus fault on unclocked MMIO access?
amlogic_tsensor_setup_hw_reset() accesses peripheral hardware registers via
regmap, but the backing clocks haven't been enabled yet. The clock enabling
seems to happen on the next line.
> + if (data->data->has_sysclk)
> + clk_prepare_enable(data->sysclk);
[Severity: High]
Should the return value of clk_prepare_enable() be checked here?
Ignoring the return value could lead to unbalanced clock references or
hardware access failures if enabling the sysclk fails during resume.
> return amlogic_thermal_enable(data);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260730-a9-thermal-v1-0-d786d37cba58@amlogic.com?part=2
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
prev parent reply other threads:[~2026-07-30 8:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 8:34 [PATCH 0/2] thermal: Add support A9 Xianwei Zhao via B4 Relay
2026-07-30 8:34 ` [PATCH 1/2] dt-bindings: thermal: amlogic: Add A9 thermal bindings Xianwei Zhao via B4 Relay
2026-07-30 8:39 ` sashiko-bot
2026-07-30 8:44 ` Xianwei Zhao
2026-07-30 8:34 ` [PATCH 2/2] thermal: amlogic: Add support for A9 thermal controller Xianwei Zhao via B4 Relay
2026-07-30 8:46 ` sashiko-bot [this message]
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=20260730084644.44D571F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xianwei.zhao@amlogic.com \
/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