From: Ian Rogers <irogers@google.com>
To: "Rajneesh Bhardwaj" <irenic.rajneesh@gmail.com>,
"Xi Pardee" <xi.pardee@linux.intel.com>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
Elkin Cruz <elkin@google.com>, Ian Rogers <irogers@google.com>
Subject: [PATCH] platform/x86/intel/pmc: Fix mode check in pmc_core_lpm_latch_mode_write()
Date: Thu, 19 Nov 2026 09:10:33 -0800 [thread overview]
Message-ID: <20261119171033.1535923-1-irogers@google.com> (raw)
In pmc_core_lpm_latch_mode_write(), when pmc->num_lpm_modes is 0 (all
S0ix substates disabled), pmc_for_each_mode(m, pmc) terminates without
assigning m. The subsequent 'if (mode != m || mode < 0)' check then
reads uninitialized stack memory for m; under zero stack
initialization (m == 0), writing "S0i2.0" (mode == 0) evaluates
'0 != 0' as false and latches a disabled substate.
Track whether mode matched an enabled substate with an explicit
boolean instead of comparing against m after the loop.
Found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig
build. Verified by building drivers/platform/x86/intel/pmc/core.o with
LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized, and with a
standalone C reproducer under ASan/UBSan; not runtime-tested on Intel
PMC hardware with disabled LPM substates.
Fixes: 8074a79fad2e ("platform/x86: intel_pmc_core: Add option to set/clear LPM mode")
Fixes: e35ee8ee498d ("platform/x86: intel/pmc: Remove unused param idx from pmc_for_each_mode()")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/platform/x86/intel/pmc/core.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c
index 47759b2a8012..7e12990d45a2 100644
--- a/drivers/platform/x86/intel/pmc/core.c
+++ b/drivers/platform/x86/intel/pmc/core.c
@@ -1147,6 +1147,7 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file,
struct pmc_dev *pmcdev = s->private;
struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
bool clear = false, c10 = false;
+ bool matched = false;
unsigned char buf[8];
int mode;
u32 reg;
@@ -1165,13 +1166,17 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file,
* 'clear'
*/
mode = sysfs_match_string(pmc_lpm_modes, buf);
+ if (mode >= 0) {
+ /* Check string matches enabled mode */
+ pmc_for_each_mode(m, pmc) {
+ if (mode == m) {
+ matched = true;
+ break;
+ }
+ }
+ }
- /* Check string matches enabled mode */
- pmc_for_each_mode(m, pmc)
- if (mode == m)
- break;
-
- if (mode != m || mode < 0) {
+ if (!matched) {
if (sysfs_streq(buf, "clear"))
clear = true;
else if (sysfs_streq(buf, "c10"))
--
2.56.1.708.g77570a6a1d-goog
reply other threads:[~2026-11-19 17:10 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=20261119171033.1535923-1-irogers@google.com \
--to=irogers@google.com \
--cc=elkin@google.com \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=irenic.rajneesh@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=platform-driver-x86@vger.kernel.org \
--cc=xi.pardee@linux.intel.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
all inboxes | Powered by JetHome®