[1/2] power: fix power management env detection

Message ID c568269db57a81ab8fecac06f81c1054f6439100.1594642553.git.anatoly.burakov@intel.com (mailing list archive)
State Superseded, archived
Headers
Series [1/2] power: fix power management env detection |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Performance-Testing fail build patch failure
ci/Intel-compilation success Compilation OK

Commit Message

Anatoly Burakov July 13, 2020, 12:15 p.m. UTC
  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 <anatoly.burakov@intel.com>
---
 lib/librte_power/power_common.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Hunt, David July 13, 2020, 12:26 p.m. UTC | #1
On 13/7/2020 1:15 PM, Anatoly Burakov wrote:
> 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 <anatoly.burakov@intel.com>
> ---
>   lib/librte_power/power_common.c | 5 +++++
>   1 file changed, 5 insertions(+)


Acked-by: David Hunt <david.hunt@intel.com)
  

Patch

diff --git a/lib/librte_power/power_common.c b/lib/librte_power/power_common.c
index 59023d986b..fd527719cd 100644
--- a/lib/librte_power/power_common.c
+++ b/lib/librte_power/power_common.c
@@ -15,6 +15,7 @@  int
 cpufreq_check_scaling_driver(const char *driver_name)
 {
 	unsigned int lcore_id = 0; /* always check core 0 */
+	size_t len;
 	char fullpath[PATH_MAX];
 	char readbuf[PATH_MAX];
 	char *s;
@@ -39,6 +40,10 @@  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 */
+	len = strnlen(readbuf, sizeof(readbuf));
+	readbuf[len - 1] = '\0';
+
 	/* does the driver name match? */
 	if (strncmp(readbuf, driver_name, sizeof(readbuf)) != 0)
 		return 0;