From 8b7b02f945e417f5348d78e523ce2c9c4f346d0b Mon Sep 17 00:00:00 2001 From: Anatoly Burakov Date: Tue, 14 Jul 2020 11:30:01 +0100 Subject: [PATCH] power: fix environment detection Anything coming from sysfs has a newline at the end. Cut it off before comparing the strings. Fixes: 20ab67608a39 ("power: add environment capability probing") Signed-off-by: Anatoly Burakov Acked-by: David Hunt Tested-by: Lihong Ma Reviewed-by: Bruce Richardson --- lib/librte_power/power_common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/librte_power/power_common.c b/lib/librte_power/power_common.c index 59023d986b..67e3318ec7 100644 --- a/lib/librte_power/power_common.c +++ b/lib/librte_power/power_common.c @@ -17,6 +17,7 @@ cpufreq_check_scaling_driver(const char *driver_name) unsigned int lcore_id = 0; /* always check core 0 */ char fullpath[PATH_MAX]; char readbuf[PATH_MAX]; + size_t end_idx; char *s; FILE *f; @@ -39,6 +40,13 @@ cpufreq_check_scaling_driver(const char *driver_name) if (s == NULL) return 0; + /* when read from sysfs, driver name has an extra newline at the end */ + end_idx = strnlen(readbuf, sizeof(readbuf)); + if (end_idx > 0 && readbuf[end_idx - 1] == '\n') { + end_idx--; + readbuf[end_idx] = '\0'; + } + /* does the driver name match? */ if (strncmp(readbuf, driver_name, sizeof(readbuf)) != 0) return 0; -- 2.20.1