diff mbox

lib: fwts_cpu: reduce scope on variables

Message ID 1438760498-15193-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Aug. 5, 2015, 7:41 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

cppcheck is reporting some minor style issues:

[src/lib/src/fwts_cpu.c:380]:
  (style) The scope of the variable 'rc' can be reduced.
[src/lib/src/fwts_cpu.c:382]:
  (style) The scope of the variable 'warned' can be reduced.

fix this by moving the declarations

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_cpu.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Ivan Hu Aug. 6, 2015, 7:12 a.m. UTC | #1
On 2015年08月05日 15:41, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> cppcheck is reporting some minor style issues:
>
> [src/lib/src/fwts_cpu.c:380]:
>    (style) The scope of the variable 'rc' can be reduced.
> [src/lib/src/fwts_cpu.c:382]:
>    (style) The scope of the variable 'warned' can be reduced.
>
> fix this by moving the declarations
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_cpu.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
> index d7793b7..a870ae8 100644
> --- a/src/lib/src/fwts_cpu.c
> +++ b/src/lib/src/fwts_cpu.c
> @@ -377,9 +377,8 @@ int fwts_cpu_benchmark(
>   	unsigned long long perfctr_result;
>   	fwts_cpu_benchmark_result tmp;
>   	cpu_set_t mask, oldset;
> -	int perfctr, ncpus, rc;
> +	int perfctr, ncpus;
>   	double duration_sec;
> -	static bool warned;
>   	bool perf_ok;
>   
>   	ncpus = fwts_cpu_enumerate();
> @@ -395,6 +394,8 @@ int fwts_cpu_benchmark(
>   	perf_ok = true;
>   	perfctr = perf_setup_counter(cpu);
>   	if (perfctr < 0) {
> +		static bool warned;
> +
>   		if (!warned) {
>   			fwts_log_warning(fw, "Can't use linux performance "
>   					"counters (perf), falling back to "
> @@ -404,9 +405,7 @@ int fwts_cpu_benchmark(
>   		perf_ok = false;
>   	}
>   
> -
>   	/* Pin to the specified CPU */
> -
>   	if (sched_getaffinity(0, sizeof(oldset), &oldset) < 0) {
>   		fwts_log_error(fw, "Cannot get scheduling affinity.");
>   		return FWTS_ERROR;
> @@ -452,7 +451,8 @@ int fwts_cpu_benchmark(
>   	tmp.loops = (1.0 * tmp.loops) / duration_sec;
>   
>   	if (perf_ok) {
> -		rc = perf_read_counter(perfctr, &perfctr_result);
> +		int rc = perf_read_counter(perfctr, &perfctr_result);
> +
>   		if (rc == FWTS_OK) {
>   			tmp.cycles = (1.0 * perfctr_result) / duration_sec;
>   			tmp.cycles_valid = true;
Acked-by: Ivan Hu <ivan.hu@canonical.com>
Alex Hung Aug. 6, 2015, 9:17 a.m. UTC | #2
On 08/05/2015 03:41 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> cppcheck is reporting some minor style issues:
> 
> [src/lib/src/fwts_cpu.c:380]:
>   (style) The scope of the variable 'rc' can be reduced.
> [src/lib/src/fwts_cpu.c:382]:
>   (style) The scope of the variable 'warned' can be reduced.
> 
> fix this by moving the declarations
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_cpu.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
> index d7793b7..a870ae8 100644
> --- a/src/lib/src/fwts_cpu.c
> +++ b/src/lib/src/fwts_cpu.c
> @@ -377,9 +377,8 @@ int fwts_cpu_benchmark(
>  	unsigned long long perfctr_result;
>  	fwts_cpu_benchmark_result tmp;
>  	cpu_set_t mask, oldset;
> -	int perfctr, ncpus, rc;
> +	int perfctr, ncpus;
>  	double duration_sec;
> -	static bool warned;
>  	bool perf_ok;
>  
>  	ncpus = fwts_cpu_enumerate();
> @@ -395,6 +394,8 @@ int fwts_cpu_benchmark(
>  	perf_ok = true;
>  	perfctr = perf_setup_counter(cpu);
>  	if (perfctr < 0) {
> +		static bool warned;
> +
>  		if (!warned) {
>  			fwts_log_warning(fw, "Can't use linux performance "
>  					"counters (perf), falling back to "
> @@ -404,9 +405,7 @@ int fwts_cpu_benchmark(
>  		perf_ok = false;
>  	}
>  
> -
>  	/* Pin to the specified CPU */
> -
>  	if (sched_getaffinity(0, sizeof(oldset), &oldset) < 0) {
>  		fwts_log_error(fw, "Cannot get scheduling affinity.");
>  		return FWTS_ERROR;
> @@ -452,7 +451,8 @@ int fwts_cpu_benchmark(
>  	tmp.loops = (1.0 * tmp.loops) / duration_sec;
>  
>  	if (perf_ok) {
> -		rc = perf_read_counter(perfctr, &perfctr_result);
> +		int rc = perf_read_counter(perfctr, &perfctr_result);
> +
>  		if (rc == FWTS_OK) {
>  			tmp.cycles = (1.0 * perfctr_result) / duration_sec;
>  			tmp.cycles_valid = true;
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
index d7793b7..a870ae8 100644
--- a/src/lib/src/fwts_cpu.c
+++ b/src/lib/src/fwts_cpu.c
@@ -377,9 +377,8 @@  int fwts_cpu_benchmark(
 	unsigned long long perfctr_result;
 	fwts_cpu_benchmark_result tmp;
 	cpu_set_t mask, oldset;
-	int perfctr, ncpus, rc;
+	int perfctr, ncpus;
 	double duration_sec;
-	static bool warned;
 	bool perf_ok;
 
 	ncpus = fwts_cpu_enumerate();
@@ -395,6 +394,8 @@  int fwts_cpu_benchmark(
 	perf_ok = true;
 	perfctr = perf_setup_counter(cpu);
 	if (perfctr < 0) {
+		static bool warned;
+
 		if (!warned) {
 			fwts_log_warning(fw, "Can't use linux performance "
 					"counters (perf), falling back to "
@@ -404,9 +405,7 @@  int fwts_cpu_benchmark(
 		perf_ok = false;
 	}
 
-
 	/* Pin to the specified CPU */
-
 	if (sched_getaffinity(0, sizeof(oldset), &oldset) < 0) {
 		fwts_log_error(fw, "Cannot get scheduling affinity.");
 		return FWTS_ERROR;
@@ -452,7 +451,8 @@  int fwts_cpu_benchmark(
 	tmp.loops = (1.0 * tmp.loops) / duration_sec;
 
 	if (perf_ok) {
-		rc = perf_read_counter(perfctr, &perfctr_result);
+		int rc = perf_read_counter(perfctr, &perfctr_result);
+
 		if (rc == FWTS_OK) {
 			tmp.cycles = (1.0 * perfctr_result) / duration_sec;
 			tmp.cycles_valid = true;