[PATCH v2 0/5] thermal/drivers/mediatek/lvts: CALSCALE, overflow, trip, and IRQ fixes

From: Ilia Snezhkov via B4 Relay

Date: Wed Dec 02 2026 - 21:20:16 EST


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@xxxxxxxxx

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)