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: 4beec1d751 ("tools/power x86_energy_perf_policy: support HWP.EPP")
Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Len Brown 2026-05-06 10:00:00 -04:00
parent db2cffbc80
commit 0177067d19

View File

@ -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;