diff mbox

Reduce the sysfs path to 2K to work around a gcc warning

Message ID 20170428172054.12689-1-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King April 28, 2017, 5:20 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

2K for a sysfs path is more than plenty of space, plus it fixes
a new funcky gcc 7 warning when building with -Wall:

cpu/cpufreq/cpufreq.c:85:26: error: ‘%s’ directive output may be
 truncated writing up to 4095 bytes into a region of size 4072
 [-Werror=format-truncation=]
   snprintf(path, len, "%s/%s/cpufreq%s%s", FWTS_CPU_PATH,...

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/cpu/cpufreq/cpufreq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Alex Hung April 28, 2017, 5:30 p.m. UTC | #1
On 2017-04-28 10:20 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 2K for a sysfs path is more than plenty of space, plus it fixes
> a new funcky gcc 7 warning when building with -Wall:
>
> cpu/cpufreq/cpufreq.c:85:26: error: ‘%s’ directive output may be
>  truncated writing up to 4095 bytes into a region of size 4072
>  [-Werror=format-truncation=]
>    snprintf(path, len, "%s/%s/cpufreq%s%s", FWTS_CPU_PATH,...
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/cpu/cpufreq/cpufreq.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index 81751866..1cfac3aa 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -51,7 +51,7 @@ typedef struct {
>
>  struct cpu {
>  	int		idx;
> -	char		sysfs_path[PATH_MAX];
> +	char		sysfs_path[2048];	/* 2K is plenty */
>  	bool		online;
>  	bool		master;
>
> @@ -85,7 +85,7 @@ static inline void cpu_mkpath(
>  	snprintf(path, len, "%s/%s/cpufreq%s%s", FWTS_CPU_PATH,
>  			cpu->sysfs_path,
>  			name ? "/" : "",
> -			name ?: "");
> +			name ? name : "");
>  }
>
>  static int cpu_set_governor(fwts_framework *fw, struct cpu *cpu,
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu May 4, 2017, 8:06 a.m. UTC | #2
On 04/29/2017 01:20 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 2K for a sysfs path is more than plenty of space, plus it fixes
> a new funcky gcc 7 warning when building with -Wall:
>
> cpu/cpufreq/cpufreq.c:85:26: error: ‘%s’ directive output may be
>  truncated writing up to 4095 bytes into a region of size 4072
>  [-Werror=format-truncation=]
>    snprintf(path, len, "%s/%s/cpufreq%s%s", FWTS_CPU_PATH,...
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/cpu/cpufreq/cpufreq.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index 81751866..1cfac3aa 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -51,7 +51,7 @@ typedef struct {
>
>  struct cpu {
>  	int		idx;
> -	char		sysfs_path[PATH_MAX];
> +	char		sysfs_path[2048];	/* 2K is plenty */
>  	bool		online;
>  	bool		master;
>
> @@ -85,7 +85,7 @@ static inline void cpu_mkpath(
>  	snprintf(path, len, "%s/%s/cpufreq%s%s", FWTS_CPU_PATH,
>  			cpu->sysfs_path,
>  			name ? "/" : "",
> -			name ?: "");
> +			name ? name : "");
>  }
>
>  static int cpu_set_governor(fwts_framework *fw, struct cpu *cpu,
>


Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
index 81751866..1cfac3aa 100644
--- a/src/cpu/cpufreq/cpufreq.c
+++ b/src/cpu/cpufreq/cpufreq.c
@@ -51,7 +51,7 @@  typedef struct {
 
 struct cpu {
 	int		idx;
-	char		sysfs_path[PATH_MAX];
+	char		sysfs_path[2048];	/* 2K is plenty */
 	bool		online;
 	bool		master;
 
@@ -85,7 +85,7 @@  static inline void cpu_mkpath(
 	snprintf(path, len, "%s/%s/cpufreq%s%s", FWTS_CPU_PATH,
 			cpu->sysfs_path,
 			name ? "/" : "",
-			name ?: "");
+			name ? name : "");
 }
 
 static int cpu_set_governor(fwts_framework *fw, struct cpu *cpu,