Linux Power Management development
 help / color / mirror / Atom feed
From: Muhammad Huda Nugroho <mhudan21@gmail.com>
To: Amit Kucheria <amitk@kernel.org>,
	Thara Gopinath <thara.gopinath@gmail.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Daniel Lezcano <daniel.lezcano@kernel.org>
Cc: Zhang Rui <rui.zhang@intel.com>,
	Lukasz Luba <lukasz.luba@arm.com>,
	linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] thermal/drivers/tsens: Drop __init from functions reachable from probe
Date: Sat, 21 Nov 2026 18:36:05 +0700	[thread overview]
Message-ID: <20261121113605.jDNtw%mhudan21@gmail.com> (raw)

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.

Signed-off-by: Muhammad Huda Nugroho <mhudan21@gmail.com>
---
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(-)

--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -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;
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -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;
 
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -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;
--- a/drivers/thermal/qcom/tsens-v2.c
+++ b/drivers/thermal/qcom/tsens-v2.c
@@ -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;
-- 
2.51.0

                 reply	other threads:[~2026-11-21 11:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261121113605.jDNtw%mhudan21@gmail.com \
    --to=mhudan21@gmail.com \
    --cc=amitk@kernel.org \
    --cc=daniel.lezcano@kernel.org \
    --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=rui.zhang@intel.com \
    --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