[dpdk-dev] [PATCH] lib/power: fix governor storage to trim newlines

Bruce Richardson bruce.richardson at intel.com
Fri Mar 29 17:24:18 CET 2019


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 at dpdk.org
> 
> Signed-off-by: David Hunt <david.hunt at 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



More information about the dev mailing list