From: Ilia Snezhkov via B4 Relay <devnull+iasnezhkov.gmail.com@kernel.org>
To: daniel.lezcano@kernel.org, rafael@kernel.org,
rui.zhang@intel.com, lukasz.luba@arm.com
Cc: matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
bchihi@baylibre.com, nfraprado@collabora.com,
linux-pm@vger.kernel.org, linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
phone-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 0/5] thermal/drivers/mediatek/lvts: CALSCALE, overflow, trip, and IRQ fixes
Date: Thu, 03 Dec 2026 02:19:56 +0000 [thread overview]
Message-ID: <20261203021956.43607-1-iasnezhkov@gmail.com> (raw)
This five-patch series fixes bugs in
drivers/thermal/mediatek/lvts_thermal.c:
1. Write LVTS_CALSCALE_CONF (0x300) to LVTS_CALSCALE instead of
overwriting a local variable and discarding it.
2. Avoid 32-bit overflow, negative left shift, and unsigned wraparound
in lvts_temp_to_raw_mt7988().
3. Serialize lvts_set_trips() with a per-controller spinlock_t so
concurrent updates across sibling thermal zones cannot race on
shared thresholds or LVTS_MONINT.
4. Recompute shared controller thresholds safely across sibling sensors
(excluding INT_MAX from winning high_thresh, falling back to the
next highest finite sibling on cooldown, matching low/high IRQ masks
independently, skipping lvts_temp_to_raw(INT_MAX), and masking
offset IRQs before writing LVTS_OFFSETL/LVTS_OFFSETH).
5. Check lvts_ctrl->sensors[i].tz before calling
thermal_zone_device_update() in lvts_ctrl_irq_handler().
---
v1: https://lore.kernel.org/r/20261126005321.71799-1-iasnezhkov@gmail.com
Changes in v2:
- Split the INT_MAX trip handling out of patch 2/5 so patch 2/5 only
fixes lvts_temp_to_raw_mt7988() (now returning 0 early when
golden_temp_offset - temperature <= 0 to avoid shifting a negative
s64) and corrected the golden_temp boundary example in its commit
message (LVTS_GOLDEN_TEMP_MAX is 62, not 64).
- Added patch 4/5 combining the INT_MAX trip handling with full sibling
threshold recomputation (lvts_recompute_thresh()), independent
low/high IRQ mask matching, leaving LVTS_OFFSETH untouched when
new_high == INT_MAX, and masking offset IRQs before writing
LVTS_OFFSETL/LVTS_OFFSETH.
- Shortened patch subjects and normalized prefix to
"thermal/drivers/mediatek/lvts:".
Testing note:
- Patches 1, 2, 3, and 5 were regression-tested on MT6789 hardware
(iKKO MindOne, factory golden_temp = 60) in an out-of-tree port of
lvts_thermal.c on ACK 6.18 (the unpopulated-tz IRQ path in patch 5
was not directly triggered on this hardware).
- The exact lvts_temp_to_raw_mt7988() boundary cases and the patch 4/5
lvts_recompute_thresh() / MMIO write-ordering state machine were
verified in a host userspace test harness under ASan and UBSan, not
directly on mainline hardware.
Found and drafted with an AI coding assistant.
Ilia Snezhkov (5):
thermal/drivers/mediatek/lvts: write LVTS_CALSCALE in configure
thermal/drivers/mediatek/lvts: fix 32-bit overflow in temp_to_raw
thermal/drivers/mediatek/lvts: serialize lvts_set_trips() per ctrl
thermal/drivers/mediatek/lvts: recompute shared trips and mask first
thermal/drivers/mediatek/lvts: skip sensors without tz in IRQ
drivers/thermal/mediatek/lvts_thermal.c | 220 +++++++++++++++---------
1 file changed, 142 insertions(+), 78 deletions(-)
--
2.54.0 (Apple Git-157)
next reply other threads:[~2026-12-03 2:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 2:19 Ilia Snezhkov via B4 Relay [this message]
2026-12-03 2:19 ` [PATCH v2 1/5] thermal/drivers/mediatek/lvts: write LVTS_CALSCALE in configure Ilia Snezhkov via B4 Relay
2026-12-03 2:19 ` [PATCH v2 2/5] thermal/drivers/mediatek/lvts: fix 32-bit overflow in temp_to_raw Ilia Snezhkov via B4 Relay
2026-12-03 2:19 ` [PATCH v2 3/5] thermal/drivers/mediatek/lvts: serialize lvts_set_trips() per ctrl Ilia Snezhkov via B4 Relay
2026-12-03 2:20 ` [PATCH v2 4/5] thermal/drivers/mediatek/lvts: recompute shared trips and mask first Ilia Snezhkov via B4 Relay
2026-12-03 2:20 ` [PATCH v2 5/5] thermal/drivers/mediatek/lvts: skip sensors without tz in IRQ Ilia Snezhkov 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=20261203021956.43607-1-iasnezhkov@gmail.com \
--to=devnull+iasnezhkov.gmail.com@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bchihi@baylibre.com \
--cc=daniel.lezcano@kernel.org \
--cc=iasnezhkov@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=matthias.bgg@gmail.com \
--cc=nfraprado@collabora.com \
--cc=phone-devel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.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