mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/x86/intel/pmc: Fix mode check in pmc_core_lpm_latch_mode_write()
@ 2026-11-19 17:10 Ian Rogers
  0 siblings, 0 replies; only message in thread
From: Ian Rogers @ 2026-11-19 17:10 UTC (permalink / raw)
  To: Rajneesh Bhardwaj, Xi Pardee, Hans de Goede, Ilpo Järvinen
  Cc: platform-driver-x86, linux-kernel, llvm, Elkin Cruz, Ian Rogers

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19 17:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:10 [PATCH] platform/x86/intel/pmc: Fix mode check in pmc_core_lpm_latch_mode_write() Ian Rogers

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®