From 0177067d195a4757149f6702af191987377c71c3 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: [PATCH] x86_energy_perf_policy: Fix optarg keyword matching Replace strncmp() with strcmp() for exact string matching in parse_optarg_string(). Exact keyword matching is safer and clearer. This prevents accidental matches with longer strings like "performance-foo". Fixes: 4beec1d75196 ("tools/power x86_energy_perf_policy: support HWP.EPP") Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- .../x86_energy_perf_policy/x86_energy_perf_policy.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c index 33de17efb4df..a6b918fff5e4 100644 --- a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c +++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c @@ -337,22 +337,22 @@ long parse_optarg_string(char *s) long i; char *endptr; - if (!strncmp(s, "default", 7)) + if (strcmp(s, "default") == 0) return OPTARG_NORMAL; - if (!strncmp(s, "normal", 6)) + if (strcmp(s, "normal") == 0) return OPTARG_NORMAL; - if (!strncmp(s, "power", 9)) + if (strcmp(s, "power") == 0) return OPTARG_POWER; - if (!strncmp(s, "balance-power", 17)) + if (strcmp(s, "balance-power") == 0) return OPTARG_BALANCE_POWER; - if (!strncmp(s, "balance-performance", 19)) + if (strcmp(s, "balance-performance") == 0) return OPTARG_BALANCE_PERFORMANCE; - if (!strncmp(s, "performance", 11)) + if (strcmp(s, "performance") == 0) return OPTARG_PERFORMANCE; errno = 0;