patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] lib/power: fix governor storage to trim newlines
@ 2019-03-29 16:11 David Hunt
  2019-03-29 16:24 ` [dpdk-stable] [dpdk-dev] " Bruce Richardson
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: David Hunt @ 2019-03-29 16:11 UTC (permalink / raw)
  To: dev; +Cc: david.hunt, anatoly.burakov, stable

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 <david.hunt@intel.com>
---
 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");
 
 	/* Check if current governor is userspace */
 	if (strncmp(buf, POWER_GOVERNOR_USERSPACE,
diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index 9c1a1625f..90a7eff35 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -292,6 +292,10 @@ power_set_governor_performance(struct pstate_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");
 
 	/* Check if current governor is performance */
 	if (strncmp(buf, POWER_GOVERNOR_PERF,
-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH] lib/power: fix governor storage to trim newlines
  2019-03-29 16:11 [dpdk-stable] [PATCH] lib/power: fix governor storage to trim newlines David Hunt
@ 2019-03-29 16:24 ` Bruce Richardson
  2019-03-29 16:25 ` [dpdk-stable] " Burakov, Anatoly
  2019-03-29 16:39 ` [dpdk-stable] [PATCH v2] " David Hunt
  2 siblings, 0 replies; 7+ messages in thread
From: Bruce Richardson @ 2019-03-29 16:24 UTC (permalink / raw)
  To: David Hunt; +Cc: dev, anatoly.burakov, stable

On Fri, Mar 29, 2019 at 04:11:42PM +0000, 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 <david.hunt@intel.com>
> ---
>  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';

Should not be needed as fgets null-terminates.

" fgets() reads in at most one less than size characters from stream and
stores them into the buffer pointed to by s.  Reading stops after an EOF or
a newline.  If a newline is read, it is stored into the buffer.  A
terminating null byte ('\0') is stored after the last character in the
buffer."

/Bruce


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [PATCH] lib/power: fix governor storage to trim newlines
  2019-03-29 16:11 [dpdk-stable] [PATCH] lib/power: fix governor storage to trim newlines David Hunt
  2019-03-29 16:24 ` [dpdk-stable] [dpdk-dev] " Bruce Richardson
@ 2019-03-29 16:25 ` Burakov, Anatoly
  2019-03-29 16:35   ` Hunt, David
  2019-03-29 16:39 ` [dpdk-stable] [PATCH v2] " David Hunt
  2 siblings, 1 reply; 7+ messages in thread
From: Burakov, Anatoly @ 2019-03-29 16:25 UTC (permalink / raw)
  To: David Hunt, dev; +Cc: stable

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 <david.hunt@intel.com>
> ---
>   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.

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [PATCH] lib/power: fix governor storage to trim newlines
  2019-03-29 16:25 ` [dpdk-stable] " Burakov, Anatoly
@ 2019-03-29 16:35   ` Hunt, David
  0 siblings, 0 replies; 7+ messages in thread
From: Hunt, David @ 2019-03-29 16:35 UTC (permalink / raw)
  To: Burakov, Anatoly, dev; +Cc: 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 <david.hunt@intel.com>
>> ---
>>   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.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [dpdk-stable] [PATCH v2] lib/power: fix governor storage to trim newlines
  2019-03-29 16:11 [dpdk-stable] [PATCH] lib/power: fix governor storage to trim newlines David Hunt
  2019-03-29 16:24 ` [dpdk-stable] [dpdk-dev] " Bruce Richardson
  2019-03-29 16:25 ` [dpdk-stable] " Burakov, Anatoly
@ 2019-03-29 16:39 ` David Hunt
  2019-03-29 17:56   ` Burakov, Anatoly
  2 siblings, 1 reply; 7+ messages in thread
From: David Hunt @ 2019-03-29 16:39 UTC (permalink / raw)
  To: dev; +Cc: david.hunt, anatoly.burakov, stable

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 <david.hunt@intel.com>
---
 lib/librte_power/power_acpi_cpufreq.c   | 2 ++
 lib/librte_power/power_pstate_cpufreq.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/lib/librte_power/power_acpi_cpufreq.c b/lib/librte_power/power_acpi_cpufreq.c
index 45412f0b9..cdcb1f613 100644
--- a/lib/librte_power/power_acpi_cpufreq.c
+++ b/lib/librte_power/power_acpi_cpufreq.c
@@ -147,6 +147,8 @@ power_set_governor_userspace(struct rte_power_info *pi)
 
 	s = fgets(buf, sizeof(buf), f);
 	FOPS_OR_NULL_GOTO(s, out);
+	/* Strip off terminating '\n' */
+	strtok(buf, "\n");
 
 	/* Check if current governor is userspace */
 	if (strncmp(buf, POWER_GOVERNOR_USERSPACE,
diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index 9c1a1625f..3e04e8040 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -292,6 +292,8 @@ power_set_governor_performance(struct pstate_power_info *pi)
 
 	s = fgets(buf, sizeof(buf), f);
 	FOPS_OR_NULL_GOTO(s, out);
+	/* Strip off terminating '\n' */
+	strtok(buf, "\n");
 
 	/* Check if current governor is performance */
 	if (strncmp(buf, POWER_GOVERNOR_PERF,
-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [PATCH v2] lib/power: fix governor storage to trim newlines
  2019-03-29 16:39 ` [dpdk-stable] [PATCH v2] " David Hunt
@ 2019-03-29 17:56   ` Burakov, Anatoly
  2019-04-01 20:24     ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
  0 siblings, 1 reply; 7+ messages in thread
From: Burakov, Anatoly @ 2019-03-29 17:56 UTC (permalink / raw)
  To: David Hunt, dev; +Cc: stable

On 29-Mar-19 4:39 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 <david.hunt@intel.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH v2] lib/power: fix governor storage to trim newlines
  2019-03-29 17:56   ` Burakov, Anatoly
@ 2019-04-01 20:24     ` Thomas Monjalon
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2019-04-01 20:24 UTC (permalink / raw)
  To: David Hunt; +Cc: dev, Burakov, Anatoly, stable

29/03/2019 18:56, Burakov, Anatoly:
> On 29-Mar-19 4:39 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 <david.hunt@intel.com>
> 
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-04-01 20:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-29 16:11 [dpdk-stable] [PATCH] lib/power: fix governor storage to trim newlines David Hunt
2019-03-29 16:24 ` [dpdk-stable] [dpdk-dev] " Bruce Richardson
2019-03-29 16:25 ` [dpdk-stable] " Burakov, Anatoly
2019-03-29 16:35   ` Hunt, David
2019-03-29 16:39 ` [dpdk-stable] [PATCH v2] " David Hunt
2019-03-29 17:56   ` Burakov, Anatoly
2019-04-01 20:24     ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon

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).