thermal/drivers/tsens: Drop __init from functions reachable from probe
Subsystems (3)
PATCH 1/1 thermal/drivers/tsens: Drop __init from functions reachable from probe
tsens_probe() calls priv->ops->init(priv), and every .init member in this driver points at a function marked __init: init_common() in tsens.c, init_8952(), init_8956() and init_tsens_v1_no_rpm() in tsens-v1.c, init_tsens_v2_no_rpm() in tsens-v2.c, and init_8226(), init_8909(), init_8939() and init_9607() in tsens-v0_1.c.
Nothing guarantees that probe runs before the init sections are freed. A deferred probe, or a platform where the tsens node is probed late, calls into freed text and oopses.
Two independent reproductions on unrelated hardware:
- On an IPQ5018 board the machine oopses roughly 9.4 s into boot inside init_tsens_v1_no_rpm(), reliably. The only way to reach userspace was to disable the tsens node in DT, which leaves the SoC with no thermal sensing at all.
- Reported separately against a Galaxy A5 SD, where the driver is built modular and resumes a deferred probe after its module init section has been freed.
Different triggers, one root cause: callbacks living in an init section that is released while the ops table still points at them.
Drop the annotation from all nine. Fixing only the entry points is not enough while the init_common() they call is still annotated. The declaration of init_common() in tsens.h never carried __init, so it needs no change.
The brace placement on init_8939() and init_8956() is corrected as well, since those lines are being touched anyway and checkpatch wants the brace on its own line.
---
Notes for reviewers, not for the commit message:
Resent: the first attempt was rejected by linux-pm for containing an HTML part, so the list never saw it. Apologies to the few of you who got that copy directly - this is the same patch, nothing has changed.
Against mainline master as of 2026-11-21. Not tested on the Galaxy A5 SD; the IPQ5018 reproduction is mine, and it was on a 6.18 kernel, where eight of these nine carry the annotation. init_8952() is newer than that tree and is included here because it has the same problem, not because I hit it.
The second reproduction is samcday's, found and fixed independently with the same mechanism:
https://github.com/samcday/linux/pull/13
I have not added a Reported-by: or Co-developed-by: for it, because I have neither their address nor their agreement to be listed. If they would like a trailer, say so and I will add it in v2 - the prior work is theirs as much as mine and I would rather credit it properly than silently.
Neither version appears to have been sent to the list before this.
No Fixes: tag: the annotations predate the ops indirection in several of these files and I could not identify a single commit that introduces the bug rather than inherits it. Happy to add one if you can point at it.
drivers/thermal/qcom/tsens.c | 2 +- drivers/thermal/qcom/tsens-v0_1.c | 9 +++++---- drivers/thermal/qcom/tsens-v1.c | 7 ++++--- drivers/thermal/qcom/tsens-v2.c | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-)
drivers/thermal/qcom/tsens.c +1 -1
@@ -929,7 +929,7 @@ .reg_stride = 4, }; -int __init init_common (struct tsens_priv *priv) +int init_common (struct tsens_priv *priv) {void __iomem *tm_base, *srot_base;struct device *dev = priv->dev;
drivers/thermal/qcom/tsens-v0_1.c +5 -4
@@ -207,7 +207,7 @@return 0 ; } -static int __init init_8226 (struct tsens_priv *priv) +static int init_8226 (struct tsens_priv *priv) { priv->sensor[0 ].slope =2901 ; priv->sensor[1 ].slope =2846 ;
@@ -219,7 +219,7 @@return init_common (priv); } -static int __init init_8909 (struct tsens_priv *priv) +static int init_8909 (struct tsens_priv *priv) {int i;
@@ -240,7 +240,8 @@return init_common (priv); } -static int __init init_8939 (struct tsens_priv *priv) { +static int init_8939 (struct tsens_priv *priv) +{ priv->sensor[0 ].slope =2911 ; priv->sensor[1 ].slope =2789 ; priv->sensor[2 ].slope =2906 ;
@@ -255,7 +256,7 @@return init_common (priv); } -static int __init init_9607 (struct tsens_priv *priv) +static int init_9607 (struct tsens_priv *priv) {int i;
drivers/thermal/qcom/tsens-v1.c +4 -3
@@ -145,7 +145,7 @@ [TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0), }; -static int __init init_8952 (struct tsens_priv *priv) +static int init_8952 (struct tsens_priv *priv) { priv->sensor[0 ].p1_calib_offset =2 ; priv->sensor[0 ].p2_calib_offset =-1 ;
@@ -173,7 +173,8 @@return init_common (priv); } -static int __init init_8956 (struct tsens_priv *priv) { +static int init_8956 (struct tsens_priv *priv) +{ priv->sensor[0 ].slope =3313 ; priv->sensor[1 ].slope =3275 ; priv->sensor[2 ].slope =3320 ;
@@ -189,7 +190,7 @@return init_common (priv); } -static int __init init_tsens_v1_no_rpm (struct tsens_priv *priv) +static int init_tsens_v1_no_rpm (struct tsens_priv *priv) {int i, ret;u32 mask =0 ;
drivers/thermal/qcom/tsens-v2.c +1 -1
@@ -220,7 +220,7 @@return 0 ; } -static int __init init_tsens_v2_no_rpm (struct tsens_priv *priv) +static int init_tsens_v2_no_rpm (struct tsens_priv *priv) {struct device *dev = priv->dev;int i, ret;
Signature · 1 line
2.51.0