From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Amit Kucheria <amitk@kernel.org>,
Thara Gopinath <thara.gopinath@gmail.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>, Rob Herring <robh@kernel.org>,
Eduardo Valentin <edubezval@gmail.com>,
Bjorn Andersson <andersson@kernel.org>,
linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 05/10] thermal/drivers/qcom/tsens: Bound sensor initialisation by num_sensors
Date: Thu, 3 Dec 2026 19:54:16 +0000 [thread overview]
Message-ID: <20261203195529.3063246-6-lee@kernel.org> (raw)
In-Reply-To: <20261203195529.3063246-1-lee@kernel.org>
tsens_probe() allocates priv->sensor[] with priv->num_sensors entries,
which may be smaller than the SoC default when #qcom,sensors is set in
Device Tree. The per-SoC init helpers for 8226, 8909, 8939, 9607,
8952, and 8956 index priv->sensor[] with hardcoded constants up to the
SoC maximum, writing past the end of the heap allocation when fewer
sensors are configured.
Replace the hardcoded assignments with static lookup tables and bound
each loop by priv->num_sensors.
Fixes: 6d7c70d1cd65 ("thermal: qcom: tsens: Allow number of sensors to come from DT")
Closes: https://sashiko.dev/#/bug/linux-f4750172-f8d0-40d4-94de-1c800cb4cc51
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/thermal/qcom/tsens-v0_1.c | 67 ++++++++++++-------------------
drivers/thermal/qcom/tsens-v1.c | 49 +++++++---------------
2 files changed, 41 insertions(+), 75 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 32d2d3e33287..468da9e513e2 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -209,69 +209,54 @@ static int calibrate_8974(struct tsens_priv *priv)
static int __init init_8226(struct tsens_priv *priv)
{
- priv->sensor[0].slope = 2901;
- priv->sensor[1].slope = 2846;
- priv->sensor[2].slope = 3038;
- priv->sensor[3].slope = 2955;
- priv->sensor[4].slope = 2901;
- priv->sensor[5].slope = 2846;
+ static const u32 slopes[] = { 2901, 2846, 3038, 2955, 2901, 2846 };
+
+ for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(slopes); i++)
+ priv->sensor[i].slope = slopes[i];
return init_common(priv);
}
static int __init init_8909(struct tsens_priv *priv)
{
- int i;
+ static const int p1_offsets[] = { 0, -10, 0, -9, -8 };
+ static const int p2_offsets[] = { 0, -6, 0, -9, -10 };
- for (i = 0; i < priv->num_sensors; ++i)
+ for (unsigned int i = 0; i < priv->num_sensors; ++i)
priv->sensor[i].slope = 3000;
- priv->sensor[0].p1_calib_offset = 0;
- priv->sensor[0].p2_calib_offset = 0;
- priv->sensor[1].p1_calib_offset = -10;
- priv->sensor[1].p2_calib_offset = -6;
- priv->sensor[2].p1_calib_offset = 0;
- priv->sensor[2].p2_calib_offset = 0;
- priv->sensor[3].p1_calib_offset = -9;
- priv->sensor[3].p2_calib_offset = -9;
- priv->sensor[4].p1_calib_offset = -8;
- priv->sensor[4].p2_calib_offset = -10;
+ for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(p1_offsets); i++) {
+ priv->sensor[i].p1_calib_offset = p1_offsets[i];
+ priv->sensor[i].p2_calib_offset = p2_offsets[i];
+ }
return init_common(priv);
}
-static int __init init_8939(struct tsens_priv *priv) {
- priv->sensor[0].slope = 2911;
- priv->sensor[1].slope = 2789;
- priv->sensor[2].slope = 2906;
- priv->sensor[3].slope = 2763;
- priv->sensor[4].slope = 2922;
- priv->sensor[5].slope = 2867;
- priv->sensor[6].slope = 2833;
- priv->sensor[7].slope = 2838;
- priv->sensor[8].slope = 2840;
- /* priv->sensor[9].slope = 2852; */
+static int __init init_8939(struct tsens_priv *priv)
+{
+ static const u32 slopes[] = {
+ 2911, 2789, 2906, 2763, 2922, 2867, 2833, 2838, 2840,
+ };
+
+ for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(slopes); i++)
+ priv->sensor[i].slope = slopes[i];
return init_common(priv);
}
static int __init init_9607(struct tsens_priv *priv)
{
- int i;
+ static const int p1_offsets[] = { 1, -4, 4, -3, -4 };
+ static const int p2_offsets[] = { 1, -2, 8, -5, -4 };
- for (i = 0; i < priv->num_sensors; ++i)
+ for (unsigned int i = 0; i < priv->num_sensors; ++i)
priv->sensor[i].slope = 3000;
- priv->sensor[0].p1_calib_offset = 1;
- priv->sensor[0].p2_calib_offset = 1;
- priv->sensor[1].p1_calib_offset = -4;
- priv->sensor[1].p2_calib_offset = -2;
- priv->sensor[2].p1_calib_offset = 4;
- priv->sensor[2].p2_calib_offset = 8;
- priv->sensor[3].p1_calib_offset = -3;
- priv->sensor[3].p2_calib_offset = -5;
- priv->sensor[4].p1_calib_offset = -4;
- priv->sensor[4].p2_calib_offset = -4;
+ for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(p1_offsets); i++) {
+ priv->sensor[i].p1_calib_offset = p1_offsets[i];
+ priv->sensor[i].p2_calib_offset = p2_offsets[i];
+ }
return init_common(priv);
}
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 12fe0fbefad4..a43ccc4bda86 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -150,44 +150,25 @@ static const struct reg_field tsens_v1_regfields[MAX_REGFIELDS] = {
static int __init init_8952(struct tsens_priv *priv)
{
- priv->sensor[0].p1_calib_offset = 2;
- priv->sensor[0].p2_calib_offset = -1;
- priv->sensor[1].p1_calib_offset = -4;
- priv->sensor[1].p2_calib_offset = -4;
- priv->sensor[2].p1_calib_offset = 4;
- priv->sensor[2].p2_calib_offset = 5;
- priv->sensor[3].p1_calib_offset = 1;
- priv->sensor[3].p2_calib_offset = 1;
- priv->sensor[4].p1_calib_offset = 2;
- priv->sensor[4].p2_calib_offset = 3;
- priv->sensor[5].p1_calib_offset = -1;
- priv->sensor[5].p2_calib_offset = -1;
- priv->sensor[6].p1_calib_offset = 0;
- priv->sensor[6].p2_calib_offset = -1;
- priv->sensor[7].p1_calib_offset = 3;
- priv->sensor[7].p2_calib_offset = 4;
- priv->sensor[8].p1_calib_offset = 2;
- priv->sensor[8].p2_calib_offset = 4;
- priv->sensor[9].p1_calib_offset = 0;
- priv->sensor[9].p2_calib_offset = 0;
- priv->sensor[10].p1_calib_offset = -3;
- priv->sensor[10].p2_calib_offset = -2;
+ static const int p1_offsets[] = { 2, -4, 4, 1, 2, -1, 0, 3, 2, 0, -3 };
+ static const int p2_offsets[] = { -1, -4, 5, 1, 3, -1, -1, 4, 4, 0, -2 };
+
+ for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(p1_offsets); i++) {
+ priv->sensor[i].p1_calib_offset = p1_offsets[i];
+ priv->sensor[i].p2_calib_offset = p2_offsets[i];
+ }
return init_common(priv);
}
-static int __init init_8956(struct tsens_priv *priv) {
- priv->sensor[0].slope = 3313;
- priv->sensor[1].slope = 3275;
- priv->sensor[2].slope = 3320;
- priv->sensor[3].slope = 3246;
- priv->sensor[4].slope = 3279;
- priv->sensor[5].slope = 3257;
- priv->sensor[6].slope = 3234;
- priv->sensor[7].slope = 3269;
- priv->sensor[8].slope = 3255;
- priv->sensor[9].slope = 3239;
- priv->sensor[10].slope = 3286;
+static int __init init_8956(struct tsens_priv *priv)
+{
+ static const u32 slopes[] = {
+ 3313, 3275, 3320, 3246, 3279, 3257, 3234, 3269, 3255, 3239, 3286,
+ };
+
+ for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(slopes); i++)
+ priv->sensor[i].slope = slopes[i];
return init_common(priv);
}
--
2.56.1.911.g883d8bcb20-goog
next prev parent reply other threads:[~2026-12-03 19:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 19:54 [PATCH 00/10] thermal: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 19:54 ` [PATCH 01/10] thermal: intel: hfi: Pass byte size to alloc_pages_exact() and free_pages_exact() Lee Jones
2026-12-03 19:54 ` [PATCH 02/10] thermal: intel: hfi: Publish hfi_instance only after successful initialisation Lee Jones
2026-12-03 19:54 ` [PATCH 03/10] thermal: int3400: Clean up ODVP attributes after unregistering thermal zone Lee Jones
2026-12-03 19:54 ` [PATCH 04/10] thermal/drivers/qcom/tsens-v1: Validate sensor count before legacy calibration Lee Jones
2026-12-03 19:54 ` Lee Jones [this message]
2026-12-03 19:54 ` [PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove Lee Jones
2026-12-03 19:54 ` [PATCH 07/10] thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp() Lee Jones
2026-12-03 19:54 ` [PATCH 08/10] tools/thermal/tmon: Open log file with O_NOFOLLOW before validating and truncating Lee Jones
2026-12-03 19:54 ` [PATCH 09/10] thermal/drivers/qcom/tsens: Drop __init from ops init callbacks Lee Jones
2026-12-03 19:54 ` [PATCH 10/10] thermal/drivers/imx91: Use pm_runtime_resume_and_get() in imx91_tmu_change_mode() Lee Jones
2026-12-03 20:21 ` Frank Li
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=20261203195529.3063246-6-lee@kernel.org \
--to=lee@kernel.org \
--cc=amitk@kernel.org \
--cc=andersson@kernel.org \
--cc=daniel.lezcano@kernel.org \
--cc=edubezval@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rui.zhang@intel.com \
--cc=stable@vger.kernel.org \
--cc=thara.gopinath@gmail.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