diff mbox

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

Message ID 1343048578-13332-2-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King July 23, 2012, 1:02 p.m. UTC
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(-)

Comments

Keng-Yu Lin July 25, 2012, 7:26 a.m. UTC | #1
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. UTC | #2
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>
diff mbox

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);
 		}