From: sashiko-bot@kernel.org
To: "Alexey Klimov" <alexey.klimov@linaro.org>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 3/3] thermal: samsung: acpm-tmu: add Exynos850 support
Date: Wed, 18 Nov 2026 14:16:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-221175@kernel.org> (raw)
In-Reply-To: <20261118-acpm-tmu-e850-support-v2-3-19848c0d97e5@linaro.org>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] thermal: samsung: acpm-tmu: uncoordinated global CORE_EN in
exynos850_tz_control()
- [Medium] thermal: samsung: acpm-tmu: zero temp_error2 fallback in
exynos850_tmu_read_trim_info()
- [Low] thermal: samsung: acpm-tmu: guard() mixed with goto in
exynos850_tmu_update_thresholds()
--
commit 4f3f530f809e63acf5e867e3d286ccbbbdd52053
Author: Alexey Klimov <alexey.klimov@linaro.org>
thermal: samsung: acpm-tmu: add Exynos850 support
This commit adds Exynos850 SoC support to the ACPM TMU driver using a mix of
ACPM IPC commands and direct MMIO register access for initialization,
threshold configuration, interrupt handling, and thermal zone control.
> diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
> index 0def0ec090841..054c99dc8250c 100644
> --- a/drivers/thermal/samsung/acpm-tmu.c
> +++ b/drivers/thermal/samsung/acpm-tmu.c
> @@ -27,6 +28,120 @@
> #define EXYNOS_TMU_SENSOR(i) BIT(i)
> #define EXYNOS_TMU_SENSORS_MAX_COUNT 16
>
> +/*
> + * Exynos850 TMU calibration type stored in the TRIMINFO CALIB_SEL field.
> + * Only two-point calibration needs special handling; anything else is
> + * treated as one-point calibration.
> + */
> +#define EXYNOS850_TMU_CAL_TWO_POINT 1
> +
> +#define EXYNOS850_TMU_TRIM_TEMP_25C 25
> +#define EXYNOS850_TMU_TRIM_TEMP_85C 85
> +#define EXYNOS850_TMU_EFUSE_VALUE 55
[ ... ]
> +/* TRIMINFO fields */
> +#define EXYNOS850_TMU_TRIMINFO_CALIB_SEL BIT(23)
> +#define EXYNOS850_TMU_TRIMINFO_25C_MASK GENMASK(8, 0)
> +#define EXYNOS850_TMU_TRIMINFO_85C_MASK GENMASK(17, 9)
[ ... ]
> @@ -158,6 +311,190 @@ static int gs101_tmu_init(struct acpm_tmu_priv *priv)
> return handle->ops->tmu.init(handle, priv->mbox_chan_id);
> }
>
> +static int exynos850_tz_control(struct acpm_tmu_sensor *sensor, bool on)
> +{
> + struct acpm_tmu_priv *priv = sensor->priv;
> +
> + return regmap_update_bits(priv->regmap, EXYNOS850_TMU_REG_CONTROL,
> + EXYNOS850_TMU_CONTROL_CORE_EN,
> + on ? EXYNOS850_TMU_CONTROL_CORE_EN : 0);
> +}
[Severity: High]
Does toggling EXYNOS850_TMU_CONTROL_CORE_EN per sensor without controller-wide
coordination disable the shared TMU core across all three Exynos850 thermal
zones?
All three groups in exynos850_sensor_groups share the single global
EXYNOS850_TMU_CONTROL_CORE_EN bit, while sensor->enabled and sensor->lock are
per-sensor. Disabling one thermal zone via acpm_tmu_change_mode() clears
EXYNOS850_TMU_CONTROL_CORE_EN globally and stops temperature sensing and
interrupts for the remaining active zones.
In addition, exynos850_tmu_update_thresholds() only checks sensor->enabled and
holds sensor->lock before toggling EXYNOS850_TMU_CONTROL_CORE_EN. During
acpm_tmu_probe(), registering sensor 1 after sensor 0 is already enabled
updates EXYNOS850_TMU_REG_THD and EXYNOS850_TMU_REG_INTEN while
EXYNOS850_TMU_CONTROL_CORE_EN is active, and concurrent trip updates on two
enabled zones race on CORE_EN:
CPU0 (sensor 0) CPU1 (sensor 1)
exynos850_tmu_update_thresholds()
lock(&sensor0->lock)
acpm_tmu_op_tz_control(false)
/* clears global CORE_EN */
exynos850_tmu_update_thresholds()
lock(&sensor1->lock)
acpm_tmu_op_tz_control(false)
...
acpm_tmu_op_tz_control(true)
/* sets global CORE_EN */
regmap_update_bits(..., REG_THD, ...)
<-- programs thresholds with CORE_EN set
> +
> +static int exynos850_tmu_read_trim_info(struct acpm_tmu_priv *priv)
> +{
> + struct regmap *regmap = priv->regmap;
> + unsigned int trim_info;
> + int i, ret;
> +
> + ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(0), &trim_info);
> + if (ret)
> + return ret;
> +
> + priv->cal_type = FIELD_GET(EXYNOS850_TMU_TRIMINFO_CALIB_SEL, trim_info);
> +
> + for (i = 0; i < priv->num_sensors; i++) {
> + struct acpm_tmu_sensor *sensor = &priv->sensors[i];
> + unsigned long mask = sensor->group->mask;
> + int t;
> +
> + for_each_set_bit(t, &mask, EXYNOS_TMU_SENSORS_MAX_COUNT) {
> + u16 temp_error1, temp_error2;
> +
> + ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(t),
> + &trim_info);
> + if (ret)
> + return ret;
> +
> + temp_error1 = FIELD_GET(EXYNOS850_TMU_TRIMINFO_25C_MASK,
> + trim_info);
> + temp_error2 = FIELD_GET(EXYNOS850_TMU_TRIMINFO_85C_MASK,
> + trim_info);
> +
> + if (temp_error1)
> + sensor->temp_error1 = temp_error1;
> + else
> + sensor->temp_error1 =
> + FIELD_GET(EXYNOS850_TMU_TRIMINFO_25C_MASK,
> + priv->data->efuse_value);
> +
> + if (priv->cal_type != EXYNOS850_TMU_CAL_TWO_POINT)
> + continue;
> +
> + if (temp_error2)
> + sensor->temp_error2 = temp_error2;
> + else
> + sensor->temp_error2 =
> + FIELD_GET(EXYNOS850_TMU_TRIMINFO_85C_MASK,
> + priv->data->efuse_value);
> + }
> + }
> +
> + return 0;
> +}
[Severity: Medium]
Does the fallback for sensor->temp_error2 always evaluate to 0?
priv->data->efuse_value is EXYNOS850_TMU_EFUSE_VALUE (55, or 0x37), so
extracting EXYNOS850_TMU_TRIMINFO_85C_MASK (GENMASK(17, 9)) yields 0. When
two-point calibration is selected and the 85C trim field in TRIMINFO is 0,
sensor->temp_error2 becomes 0 and exynos850_temp_to_code() computes
(sensor->temp_error2 - sensor->temp_error1) with a negative slope, producing
bogus threshold codes in exynos850_tmu_update_thresholds().
[ ... ]
> @@ -246,6 +583,90 @@ static int acpm_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
> return 0;
> }
[ ... ]
> +static int exynos850_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
> + u8 thresholds[2], u8 inten)
> +{
> + struct acpm_tmu_priv *priv = sensor->priv;
> + unsigned long mask = sensor->group->mask;
> + bool was_enabled;
> + int ret = 0, restore_ret, i, trip_code, trip_code_low;
> + u32 addr;
> +
> + guard(mutex)(&sensor->lock);
> +
> + was_enabled = sensor->enabled;
> +
> + if (was_enabled) {
> + ret = acpm_tmu_op_tz_control(sensor, false);
> + if (ret)
> + return ret;
> + }
> +
> + trip_code = exynos850_temp_to_code(sensor, thresholds[1]);
> + trip_code_low = exynos850_temp_to_code(sensor, thresholds[0]);
> +
> + for_each_set_bit(i, &mask, EXYNOS_TMU_SENSORS_MAX_COUNT) {
> + u32 irq_en = 0;
> +
> + if (inten & BIT(0)) {
> + addr = EXYNOS850_TMU_REG_THD(i) +
> + EXYNOS850_TMU_THD_FALL1_OFFSET;
> + ret = regmap_update_bits(priv->regmap, addr,
> + EXYNOS850_TMU_THD_LEVEL1_MASK,
> + FIELD_PREP(EXYNOS850_TMU_THD_LEVEL1_MASK,
> + trip_code_low));
> + if (ret)
> + goto out_restore;
> + irq_en = EXYNOS850_TMU_INTEN_FALL1;
> + }
> +
> + if (inten & BIT(1)) {
> + addr = EXYNOS850_TMU_REG_THD(i) +
> + EXYNOS850_TMU_THD_RISE1_OFFSET;
> + ret = regmap_update_bits(priv->regmap, addr,
> + EXYNOS850_TMU_THD_LEVEL1_MASK,
> + FIELD_PREP(EXYNOS850_TMU_THD_LEVEL1_MASK,
> + trip_code));
> + if (ret)
> + goto out_restore;
> + irq_en |= EXYNOS850_TMU_INTEN_RISE1;
> + }
> +
> + ret = regmap_update_bits(priv->regmap, EXYNOS850_TMU_REG_INTEN(i),
> + EXYNOS850_TMU_INTEN_FALL1 |
> + EXYNOS850_TMU_INTEN_RISE1, irq_en);
> + if (ret)
> + goto out_restore;
> + }
> +
> +out_restore:
> + if (was_enabled) {
> + restore_ret = acpm_tmu_op_tz_control(sensor, true);
> + if (restore_ret) {
> + dev_err(priv->dev, "Failed to restore sensor state: %d\n",
> + restore_ret);
> + if (!ret)
> + ret = restore_ret;
> + }
> + }
> +
> + return ret;
> +}
[Severity: Low]
This isn't a bug, but exynos850_tmu_update_thresholds() mixes
guard(mutex)(&sensor->lock) with goto out_restore. Using break inside the
for_each_set_bit() loop would avoid mixing scope-based cleanup with goto
error handling.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-acpm-tmu-e850-support-v2-0-19848c0d97e5@linaro.org?part=3
prev parent reply other threads:[~2026-11-18 14:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 13:51 [PATCH v2 0/3] thermal: samsung: acpm-tmu: Add Exynos850 support Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 1/3] dt-bindings: thermal: gs101-tmu: add Exynos850 compatible Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 2/3] thermal: samsung: acpm-tmu: refactor SoC-specific operations into driver data Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 3/3] thermal: samsung: acpm-tmu: add Exynos850 support Alexey Klimov
2026-11-18 14:16 ` 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=sashiko-outbox-221175@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexey.klimov@linaro.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox