From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796264399; b=3wBOnXFtSTYXaeT1+ffKasstpoCZF0bJxTIyAf/+Nb9s/SXlyu0zBiuS1FvuhBrDsYkK B3QugU//pK+N8bQI4ep9QAhi5vSivO81/2nTsjLvEEzio6lu0jAPjcBsauLDHDMqwTUUf atyQ1L/oUrhTiIqhIqFMZYb1I+YiI/SM/R3qiuBWY8gOsnrBIVKeMp/UtOW/cncw2acw2 B9cbGC3p9lAlXOa85WdXYHSaWDaEjRcDBXRT5jByZFc/Nxo0u29ZHi7z+I2COt1Kz+nym SdTKbsIECHgYfWwIsxe7VtWnNuaJDS9YLwW3XtKNgBzPsECt1k1Rb6D1TRfx3aWuXsg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796264399; h=Received:DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-Id: In-Reply-To:References:MIME-Version:Content-Type:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=lj2+cu8YjyXRAzl/9cxHan7SLFf0Zf4Tt9VRQ1ijL38=; b=4OMgUAxrDE2jDLkjm+EwoRuOa4sziuSsElPxHNblIzHwE2tAJt3/IRkeTZO5+xeEKr0v tvns/HumqigqHTeKEGpDDml8qYngj0ng3nzf+QDqwf+FgJGHvsxtUeyy/NmWNnN0m4BZe GVGdNb9gi9ETNYEvqrksGIbzlKj4ihIUmoYYxobyQKwu1uNiDR+qa6b0HPHrMIu5tCm+J 61YCpNvAWJvS8YEsPClengLyRYCpXC41Ig8q1CWMpjuxEkX8asaBLZl/n4uyDTzljDV36 3dT1rZUXVd5KWRRr5HCA22iSZjx5x/QyLDBce/JQxhmIdLJ+wEDX7EtamI+6QKWkeTw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QIgfUVNB; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DB6B606A32D; Thu, 3 Dec 2026 02:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QIgfUVNB Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796264399; b=Nh9VMozm+0bsyKCZDxSgbEZ1zEab4S+PArwOtPtGZL3UhWlb8UGpGtp4xefXWbs/DPzs Kh/xQbMcu4umfBngL2KTK7OAG22yKph1EFTxwSQtnrj0Re8xnFFXFsVV5VvWgkZdSnzII lu72megtSs7uLCvy0KqkheUyC3krT3xpzvkkzqVOTIL4bOon0/xm0NNA07E+uZVtcjkGZ R1gAwj08ix/PJO9/ww62XBLvbksWg3hVokDKmQFoVJmRQJQXOcXOav1E8CjVhSRZZ+ip2 0eI9ptjFk8Kx9AAmBZqpwXhPjzDBi/rg+zBjH3cHNcjOocAYBmkanmYSPvjBOLZrwkw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796264399; h=DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-Id: In-Reply-To:References:MIME-Version:Content-Type:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=lj2+cu8YjyXRAzl/9cxHan7SLFf0Zf4Tt9VRQ1ijL38=; b=wBbTC5D6Mj3sQE8ThN/GhXqqIWkkA0mJQQQzUFZh8MBUOhgcIFCnDswyhD8eXMu+NPVl 687EmSvm3SyNQbNwxF97i+BMmEQBfuNUENVMuq+vqX9xYdKaFz6fAlx5i4ZRMPEdNTJXZ bFx95c2PeqNXVi41UzkhhEiqgegYR3aoDRF7ed0xcvpEUAM8qAFVQbRW6PYYsOFNs9SCN Ei9YUpoFUJoxEuNargIXfCNGIJe74KJn0BtgTGL2lFZJFsGWHl+hOOK+IZPPpnssdONf9 6bGHIHTavFeMtzZ+IMg99o2ROtlvCOIxAd+dZxl7L3RE82yUGuvKJelSCPh6GAmn2ng== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 6BA501F00896; Thu, 3 Dec 2026 02:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796264399; bh=lj2+cu8YjyXRAzl/9cxHan7SLFf0Zf4Tt9VRQ1ijL38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=QIgfUVNBy+9h23jM+cL5SVsN5mUXaFY4S+SaNLpXcE1+YkOpLTUx2dfuE5Uempt06 cw6mTcL1zNCcF62+NWTXLv7Lyoh9cKlqP+tyHVekXBLkGy7jt7GduVYE3SThc2LzU1 6dTzDq7kBooOCvY7wCfixJso8MDeBFyHnbXknFY0HsA554HkB0RCnWREdyKWEFM1KW y8O3S1z88VOlm6R/7IdQhBgJs4wDU1erV0DAqLPsuNWwyAkumkPikD9Bhb3XMS0TvL hU/WnRamFllPAiYrtdW8+fXtemh299o458Cl+z18I6AoQobG/sISGvCeRGMnE7mhjO E6CLMmREAlXMQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id EBB764F754; Thu, 3 Dec 2026 02:19:57 +0000 (UTC) From: Ilia Snezhkov via B4 Relay 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 Message-Id: <20261203021956.43607-4-iasnezhkov@gmail.com> In-Reply-To: <20261203021956.43607-1-iasnezhkov@gmail.com> References: <20261203021956.43607-1-iasnezhkov@gmail.com> X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796264396; l=2410; i=iasnezhkov@gmail.com; s=mindone2026; h=from:subject:message-id; bh=UA2uf0fWs08E58FTdOaKbB2OPmO8L5ckiPmUlNVnhTo=; b=6uCA0rL/z8AOMCahPpIRQiuAK6SU5dgT2uNGfzeTKQGU8ROROMdIxyrCyL3TLWBQ28aZZoLR2 F22MMrmqVHJCH+UUixaLyfhNXxYBlzOy+MwkiPQ2qsXSmUq0WXCGPMd X-Developer-Key: i=iasnezhkov@gmail.com; a=ed25519; pk=hQgXfiWi4ukk2jh4BHu1vRVhg9BUivo//AFp50AKMag= X-Endpoint-Received: by B4 Relay for iasnezhkov@gmail.com/mindone2026 with auth_id=1643 X-Original-From: Ilia Snezhkov Reply-To: iasnezhkov@gmail.com Content-Transfer-Encoding: 7bit From: Ilia Snezhkov 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 --- 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 */ +#include #include #include #include @@ -16,6 +17,7 @@ #include #include #include +#include #include #include @@ -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)