DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: dev@dpdk.org, David Hunt <david.hunt@intel.com>, reshma.pattan@intel.com
Subject: Re: [dpdk-dev] [PATCH v2 1/2] power: fix power management env detection
Date: Tue, 14 Jul 2020 10:34:05 +0100	[thread overview]
Message-ID: <8f11d232-1484-c62b-f970-53c114518d15@intel.com> (raw)
In-Reply-To: <20200713153321.GJ694@bricha3-MOBL.ger.corp.intel.com>

On 13-Jul-20 4:33 PM, Bruce Richardson wrote:
> On Mon, Jul 13, 2020 at 03:54:27PM +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>
>> ---
>>   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..22b016ca9d 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 end_idx;
>>   	char fullpath[PATH_MAX];
>>   	char readbuf[PATH_MAX];
>>   	char *s;
>> @@ -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));
>> +	/* prevent underflow if len is zero */
>> +	if (end_idx > 0)
>> +		end_idx--;
>> +	readbuf[end_idx] = '\0';
>> +
> Would it not be safer to add " && readbuf[end_idx - 1] == '\n'" to the
> condition, to check that it's terminated as expected? Theoretically if we
> had a long string returned which was truncated, or only just fit, there
> would not be a '\n' at the end.
> 
> /Bruce
> 

Yep, true, however unlikely :) I'll submit a v3.

-- 
Thanks,
Anatoly

  reply	other threads:[~2020-07-14  9:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13 12:15 [dpdk-dev] [PATCH " Anatoly Burakov
2020-07-13 12:15 ` [dpdk-dev] [PATCH 2/2] l3fwd-power: fix updating performance lcore parameters Anatoly Burakov
2020-07-13 12:29   ` Hunt, David
2020-07-13 12:26 ` [dpdk-dev] [PATCH 1/2] power: fix power management env detection Hunt, David
2020-07-13 14:54 ` [dpdk-dev] [PATCH v2 " Anatoly Burakov
2020-07-13 15:33   ` Bruce Richardson
2020-07-14  9:34     ` Burakov, Anatoly [this message]
2020-07-14 10:30   ` [dpdk-dev] [PATCH v3 " Anatoly Burakov
2020-07-15  4:18     ` Ma, LihongX
2020-07-17 12:50     ` Bruce Richardson
2020-07-21 23:57       ` Thomas Monjalon
2020-07-14 10:30   ` [dpdk-dev] [PATCH v3 2/2] l3fwd-power: fix updating performance lcore parameters Anatoly Burakov
2020-07-13 14:54 ` [dpdk-dev] [PATCH v2 " Anatoly Burakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8f11d232-1484-c62b-f970-53c114518d15@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    --cc=reshma.pattan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).