From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B694DA0543; Tue, 14 Jul 2020 12:30:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9B2A31D5B6; Tue, 14 Jul 2020 12:30:06 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id E7BAA1D5B1 for ; Tue, 14 Jul 2020 12:30:04 +0200 (CEST) IronPort-SDR: WTxmY/njQ7mkNYpLDu8BEMS9DDI5eo45g9td7TnnoMFjWIOtFUHILgeqWt3H57SVxEendxM7pL sjvirDkbJjkg== X-IronPort-AV: E=McAfee;i="6000,8403,9681"; a="146342808" X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="146342808" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2020 03:30:01 -0700 IronPort-SDR: 6yracQH3rskNl+qKEvDaIYDSGeiykQKIULxt8JuBavA3tYc/WdPKiaH1GnPHQu7Gu50P4aBTBU k1fwkZE6H5rw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="324506201" Received: from silpixa00399498.ir.intel.com (HELO silpixa00399498.ger.corp.intel.com) ([10.237.222.52]) by FMSMGA003.fm.intel.com with ESMTP; 14 Jul 2020 03:30:02 -0700 From: Anatoly Burakov To: dev@dpdk.org Cc: David Hunt , reshma.pattan@intel.com, bruce.richardson@intel.com Date: Tue, 14 Jul 2020 11:30:01 +0100 Message-Id: <7fcd224245cddd24d5457f1d6ba29c563006c4d6.1594722597.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <42bebf7cebd2b635a60b626faf605df6d8a277c1.1594652063.git.anatoly.burakov@intel.com> References: <42bebf7cebd2b635a60b626faf605df6d8a277c1.1594652063.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH v3 1/2] power: fix power management env detection X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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(+) 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.17.1