Patchwork [1/8] cpu: cpufreq: cpufreq and cpuidle dirs confusing cpuN parsing

login
register
mail settings
Submitter Colin King
Date July 23, 2012, 1:02 p.m.
Message ID <1343048578-13332-2-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/172663/
State Accepted
Headers show

Comments

Colin King - July 23, 2012, 1:02 p.m.
From: Colin Ian King <colin.king@canonical.com>

We need to only exercise CPUs in the path /sys/devices/system/cpu
when the directory matches cpuN (where N is a number).  Add an
extra check so we don't get fooled by cpufreq and cpuidle dir names
in /sys/devices/system/cpu

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/cpu/cpufreq/cpufreq.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
Keng-Yu Lin - July 25, 2012, 7:26 a.m.
On Mon, Jul 23, 2012 at 9:02 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> We need to only exercise CPUs in the path /sys/devices/system/cpu
> when the directory matches cpuN (where N is a number).  Add an
> extra check so we don't get fooled by cpufreq and cpuidle dir names
> in /sys/devices/system/cpu
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/cpu/cpufreq/cpufreq.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index d2c5281..a141812 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -36,6 +36,7 @@
>  #include <sched.h>
>  #include <time.h>
>  #include <math.h>
> +#include <ctype.h>
>
>  #define FWTS_CPU_PATH  "/sys/devices/system/cpu"
>
> @@ -626,7 +627,7 @@ static int cpufreq_test1(fwts_framework *fw)
>         }
>
>         while ((entry = readdir(dir)) != NULL) {
> -               if (entry && strlen(entry->d_name)>3) {
> +               if (entry && strlen(entry->d_name)>3 && isdigit(entry->d_name[3])) {
>                         cpu = strtoul(entry->d_name+3,NULL,10);
>                         lowest_speed(fw, cpu);
>                 }
> @@ -636,7 +637,7 @@ static int cpufreq_test1(fwts_framework *fw)
>         /* then do the benchmark */
>
>         while ((entry = readdir(dir)) != NULL) {
> -               if (entry && strlen(entry->d_name)>3) {
> +               if (entry && strlen(entry->d_name)>3 && isdigit(entry->d_name[3])) {
>                         cpu = strtoul(entry->d_name+3,NULL,10);
>                         do_cpu(fw, cpu);
>                         lowest_speed(fw, cpu);
> @@ -649,7 +650,7 @@ static int cpufreq_test1(fwts_framework *fw)
>         /* set everything back to the highest speed again */
>
>         while ((entry = readdir(dir)) != NULL) {
> -               if (entry && strlen(entry->d_name)>3) {
> +               if (entry && strlen(entry->d_name)>3 && isdigit(entry->d_name[3])) {
>                         cpu = strtoul(entry->d_name+3,NULL,10);
>                         highest_speed(fw, cpu);
>                 }
> --
> 1.7.10.4
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Ivan Hu - July 25, 2012, 8:01 a.m.
On 07/23/2012 09:02 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> We need to only exercise CPUs in the path /sys/devices/system/cpu
> when the directory matches cpuN (where N is a number).  Add an
> extra check so we don't get fooled by cpufreq and cpuidle dir names
> in /sys/devices/system/cpu
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/cpu/cpufreq/cpufreq.c |    7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index d2c5281..a141812 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -36,6 +36,7 @@
>   #include <sched.h>
>   #include <time.h>
>   #include <math.h>
> +#include <ctype.h>
>
>   #define FWTS_CPU_PATH	"/sys/devices/system/cpu"
>
> @@ -626,7 +627,7 @@ static int cpufreq_test1(fwts_framework *fw)
>   	}
>
>   	while ((entry = readdir(dir)) != NULL) {
> -		if (entry && strlen(entry->d_name)>3) {
> +		if (entry && strlen(entry->d_name)>3 && isdigit(entry->d_name[3])) {
>   			cpu = strtoul(entry->d_name+3,NULL,10);
>   			lowest_speed(fw, cpu);
>   		}
> @@ -636,7 +637,7 @@ static int cpufreq_test1(fwts_framework *fw)
>   	/* then do the benchmark */
>
>   	while ((entry = readdir(dir)) != NULL) {
> -		if (entry && strlen(entry->d_name)>3) {
> +		if (entry && strlen(entry->d_name)>3 && isdigit(entry->d_name[3])) {
>   			cpu = strtoul(entry->d_name+3,NULL,10);
>   			do_cpu(fw, cpu);
>   			lowest_speed(fw, cpu);
> @@ -649,7 +650,7 @@ static int cpufreq_test1(fwts_framework *fw)
>   	/* set everything back to the highest speed again */
>
>   	while ((entry = readdir(dir)) != NULL) {
> -		if (entry && strlen(entry->d_name)>3) {
> +		if (entry && strlen(entry->d_name)>3 && isdigit(entry->d_name[3])) {
>   			cpu = strtoul(entry->d_name+3,NULL,10);
>   			highest_speed(fw, cpu);
>   		}
>

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

Patch

diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
index d2c5281..a141812 100644
--- a/src/cpu/cpufreq/cpufreq.c
+++ b/src/cpu/cpufreq/cpufreq.c
@@ -36,6 +36,7 @@ 
 #include <sched.h>
 #include <time.h>
 #include <math.h>
+#include <ctype.h>
 
 #define FWTS_CPU_PATH	"/sys/devices/system/cpu"
 
@@ -626,7 +627,7 @@  static int cpufreq_test1(fwts_framework *fw)
 	}
 
 	while ((entry = readdir(dir)) != NULL) {
-		if (entry && strlen(entry->d_name)>3) {
+		if (entry && strlen(entry->d_name)>3 && isdigit(entry->d_name[3])) {
 			cpu = strtoul(entry->d_name+3,NULL,10);
 			lowest_speed(fw, cpu);
 		}
@@ -636,7 +637,7 @@  static int cpufreq_test1(fwts_framework *fw)
 	/* then do the benchmark */
 
 	while ((entry = readdir(dir)) != NULL) {
-		if (entry && strlen(entry->d_name)>3) {
+		if (entry && strlen(entry->d_name)>3 && isdigit(entry->d_name[3])) {
 			cpu = strtoul(entry->d_name+3,NULL,10);
 			do_cpu(fw, cpu);
 			lowest_speed(fw, cpu);
@@ -649,7 +650,7 @@  static int cpufreq_test1(fwts_framework *fw)
 	/* set everything back to the highest speed again */
 
 	while ((entry = readdir(dir)) != NULL) {
-		if (entry && strlen(entry->d_name)>3) {
+		if (entry && strlen(entry->d_name)>3 && isdigit(entry->d_name[3])) {
 			cpu = strtoul(entry->d_name+3,NULL,10);
 			highest_speed(fw, cpu);
 		}