From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id A10AEA05D3 for ; Fri, 29 Mar 2019 17:35:20 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 655294CC3; Fri, 29 Mar 2019 17:35:20 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 87BC34CA6; Fri, 29 Mar 2019 17:35:15 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2019 09:35:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,285,1549958400"; d="scan'208";a="131316590" Received: from dhunt5-mobl2.ger.corp.intel.com (HELO [10.237.210.26]) ([10.237.210.26]) by orsmga006.jf.intel.com with ESMTP; 29 Mar 2019 09:35:13 -0700 To: "Burakov, Anatoly" , dev@dpdk.org Cc: stable@dpdk.org References: <20190329161142.39787-1-david.hunt@intel.com> From: "Hunt, David" Message-ID: Date: Fri, 29 Mar 2019 16:35:12 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [dpdk-stable] [PATCH] lib/power: fix governor storage to trim newlines X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi Anatoly, On 29/3/2019 4:25 PM, Burakov, Anatoly wrote: > On 29-Mar-19 4:11 PM, David Hunt wrote: >> Currently the Power Libray stores the governor name with an embedded >> newline read from the scaling_governor sysfs file. This patch strips >> it out. >> >> Fixes: 445c6528b55f ("power: common interface for guest and host") >> Cc: stable@dpdk.org >> >> Signed-off-by: David Hunt >> --- >>   lib/librte_power/power_acpi_cpufreq.c   | 4 ++++ >>   lib/librte_power/power_pstate_cpufreq.c | 4 ++++ >>   2 files changed, 8 insertions(+) >> >> diff --git a/lib/librte_power/power_acpi_cpufreq.c >> b/lib/librte_power/power_acpi_cpufreq.c >> index 45412f0b9..c2febdf06 100644 >> --- a/lib/librte_power/power_acpi_cpufreq.c >> +++ b/lib/librte_power/power_acpi_cpufreq.c >> @@ -147,6 +147,10 @@ power_set_governor_userspace(struct >> rte_power_info *pi) >>         s = fgets(buf, sizeof(buf), f); >>       FOPS_OR_NULL_GOTO(s, out); >> +    buf[BUFSIZ-1] = '\0'; >> +    if (strlen(buf)) >> +        /* Strip off terminating '\n' */ >> +        strtok(buf, "\n"); > > I have a feeling that either strlen or strtok here is unnecessary. > > If it's always terminating - you can just use strlen return value and > overwrite the '\n' without going over the string the second time - you > know where the string ends! > > You have already written null-terminator to the end of the buffer, so > it can't overflow on strtok, so you don't really need strlen either, > because the string will either: > > 1) be empty (in which case strtok does nothing) > 2) contain text + newline (in which case you cut off the newline and > leave the text - no need for strlen), or > 3) contain just a newline (which would make it empty after strtok) > > Did you mean to only cut off the newline off the strings that have > stuff other than newline? That would be the only case where using > strlen would make sense - in which case, not only the check is wrong, > but you could also replace it with a simple 'if (buf[0] != '\n')' > check instead of strlen. > So just the strtok() then, without anything else (apart from the comment) . Sure! :) Thanks, Dave.