[PATCH 04/10] thermal/drivers/qcom/tsens-v1: Validate sensor count before legacy calibration

From: Lee Jones

Date: Thu Dec 03 2026 - 14:56:10 EST


data_tsens_v1 allows up to 11 sensors via tsens_v1_feat.max_sensors,
whereas calibrate_v1() passes 10-element stack arrays p1[10] and p2[10]
and the 10-entry tsens_qcs404_nvmem table to
tsens_read_calibration_legacy() and compute_intercept_slope(). With 11
sensors configured, both read past tsens_qcs404_nvmem.sp and overflow
p1 and p2 on the stack.

Reject legacy calibration in calibrate_v1() when priv->num_sensors
exceeds ARRAY_SIZE(p1).

Fixes: e8c24c6f5d1c ("drivers: thermal: tsens: Add generic support for TSENS v1 IP")
Closes: https://sashiko.dev/#/bug/linux-cb651f32-9e59-4f52-9175-a61de369ed59
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/thermal/qcom/tsens-v1.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 7bda8e6087c4..12fe0fbefad4 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -49,8 +49,11 @@ static int calibrate_v1(struct tsens_priv *priv)
int mode, ret;

ret = tsens_calibrate_common(priv);
- if (!ret)
- return 0;
+ if (!ret || ret == -EPROBE_DEFER)
+ return ret;
+
+ if (priv->num_sensors > ARRAY_SIZE(p1))
+ return -EINVAL;

qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(qfprom_cdata))
--
2.56.1.911.g883d8bcb20-goog