Linux Power Management development
 help / color / mirror / Atom feed
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 3/5] thermal/drivers/mediatek/lvts: serialize lvts_set_trips() per ctrl
Date: Thu, 03 Dec 2026 02:19:59 +0000	[thread overview]
Message-ID: <20261203021956.43607-4-iasnezhkov@gmail.com> (raw)
In-Reply-To: <20261203021956.43607-1-iasnezhkov@gmail.com>

From: Ilia Snezhkov <iasnezhkov@gmail.com>

Each struct lvts_ctrl manages up to four sensors, each registered as an
independent thermal_zone_device with its own tz->lock. Concurrent
lvts_set_trips() calls for sensors sharing a controller therefore run
without mutual exclusion while updating lvts_ctrl->{low,high}_thresh,
performing a read-modify-write on LVTS_MONINT in lvts_update_irq_mask(),
and writing LVTS_OFFSETL and LVTS_OFFSETH.

Two concurrent callers can lose each other's LVTS_MONINT enable bits or
leave the programmed threshold registers inconsistent with the stored
controller thresholds.

Add a per-controller spinlock_t to struct lvts_ctrl and serialize
lvts_set_trips() with guard(spinlock)(&lvts_ctrl->lock).

Fixes: 2bba1acf7a4c ("thermal/drivers/mediatek/lvts_thermal: Manage threshold between sensors")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
No code changes since v1.
Found and drafted with an AI coding assistant.

 drivers/thermal/mediatek/lvts_thermal.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 6d39025..aaadc00 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -4,6 +4,7 @@
  * Author: Balsam CHIHI <bchihi@baylibre.com>
  */
 
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
 #include <linux/delay.h>
@@ -16,6 +17,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/spinlock.h>
 #include <linux/thermal.h>
 #include <dt-bindings/thermal/mediatek,lvts-thermal.h>
 
@@ -181,6 +183,7 @@ struct lvts_ctrl {
 	void __iomem *base;
 	int low_thresh;
 	int high_thresh;
+	spinlock_t lock; /* protects thresholds and LVTS_MONINT */
 };
 
 struct lvts_domain {
@@ -451,6 +454,8 @@ static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
 	u32 raw_high = lvts_temp_to_raw(high, lvts_data);
 	bool should_update_thresh;
 
+	guard(spinlock)(&lvts_ctrl->lock);
+
 	lvts_sensor->low_thresh = low;
 	lvts_sensor->high_thresh = high;
 
@@ -987,6 +992,7 @@ static int lvts_ctrl_init(struct device *dev, struct lvts_domain *lvts_td,
 
 		lvts_ctrl[i].low_thresh = INT_MIN;
 		lvts_ctrl[i].high_thresh = INT_MIN;
+		spin_lock_init(&lvts_ctrl[i].lock);
 	}
 
 	/*
-- 
2.54.0 (Apple Git-157)




  parent reply	other threads:[~2026-12-03  2:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  2:19 [PATCH v2 0/5] thermal/drivers/mediatek/lvts: CALSCALE, overflow, trip, and IRQ fixes Ilia Snezhkov via B4 Relay
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 ` Ilia Snezhkov via B4 Relay [this message]
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-4-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