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

Message ID 7fcd224245cddd24d5457f1d6ba29c563006c4d6.1594722597.git.anatoly.burakov@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v3,1/2] power: fix power management env detection |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS

Commit Message

Burakov, Anatoly July 14, 2020, 10:30 a.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>
Acked-by: David Hunt <david.hunt@intel.com>
---

Notes:
    v3:
    - Check if last character is really a newline before removing it
    
    v2:
    - Fix potential integer underflow

 lib/librte_power/power_common.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Ma, LihongX July 15, 2020, 4:18 a.m. UTC | #1
Tested-by:ma,Lihong<lihongx.ma@intel.com>

Regards,
Ma,lihong

-----Original Message-----
From: dev <dev-bounces@dpdk.org> On Behalf Of Anatoly Burakov
Sent: Tuesday, July 14, 2020 6:30 PM
To: dev@dpdk.org
Cc: Hunt, David <david.hunt@intel.com>; Pattan, Reshma <reshma.pattan@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>
Subject: [dpdk-dev] [PATCH v3 1/2] power: fix power management env 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 <anatoly.burakov@intel.com>
Acked-by: David Hunt <david.hunt@intel.com>
---

Notes:
    v3:
    - Check if last character is really a newline before removing it
    
    v2:
    - Fix potential integer underflow

 lib/librte_power/power_common.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  
Bruce Richardson July 17, 2020, 12:50 p.m. UTC | #2
On Tue, Jul 14, 2020 at 11:30:01AM +0100, 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>
> Acked-by: David Hunt <david.hunt@intel.com>
> ---
Reviewed-by: Bruce Richardson <bruce.richardson@intel.com>
  
Thomas Monjalon July 21, 2020, 11:57 p.m. UTC | #3
17/07/2020 14:50, Bruce Richardson:
> On Tue, Jul 14, 2020 at 11:30:01AM +0100, 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>
> > Acked-by: David Hunt <david.hunt@intel.com>
> > ---
> Reviewed-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks
  

Patch

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;