diff mbox

[22/46] cpu: nx: reduce scope of variables

Message ID 1421175905-17035-23-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Jan. 13, 2015, 7:04 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

cppcheck is picking up some minor style issues which can
be easily fixed:

[src/cpu/nx/nx.c:80]:
	(style) The scope of the variable 'fwts_nx_cpuinfo' can be reduced.
[src/cpu/nx/nx.c:133]:
	(style) The scope of the variable 'fwts_nx_cpuinfo' can be reduced.

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

Comments

Ivan Hu Jan. 15, 2015, 7:33 a.m. UTC | #1
On 01/14/2015 03:04 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> cppcheck is picking up some minor style issues which can
> be easily fixed:
>
> [src/cpu/nx/nx.c:80]:
> 	(style) The scope of the variable 'fwts_nx_cpuinfo' can be reduced.
> [src/cpu/nx/nx.c:133]:
> 	(style) The scope of the variable 'fwts_nx_cpuinfo' can be reduced.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/cpu/nx/nx.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/src/cpu/nx/nx.c b/src/cpu/nx/nx.c
> index f2fb4ed..4bdcb55 100644
> --- a/src/cpu/nx/nx.c
> +++ b/src/cpu/nx/nx.c
> @@ -77,7 +77,6 @@ static int nx_test1(fwts_framework *fw)
>
>   static int nx_test2(fwts_framework *fw)
>   {
> -	fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
>   	int i;
>   	int n;
>   	int cpu0_has_nx = 0;
> @@ -98,7 +97,9 @@ static int nx_test2(fwts_framework *fw)
>   		return FWTS_OK;
>   	}
>
> -	for (i=0; i<n; i++) {
> +	for (i = 0; i < n; i++) {
> +		fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
> +
>   		if ((fwts_nx_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
>   			fwts_failed(fw, LOG_LEVEL_MEDIUM, "NXCPUInfoRead", "Cannot get CPU%d info", i);
>   			fwts_cpu_free_info(fwts_nx_cpuinfo);
> @@ -130,7 +131,6 @@ static int nx_test3(fwts_framework *fw)
>   	int failed = 0;
>   	uint64_t msr_value = 0;
>   	const uint64_t nx_bit = 1ULL << 34;
> -	fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
>
>   	fwts_log_info(fw,
>   		"This test verifies that all CPUs have the same NX flag setting by examining the per CPU MSR register 0x1a0.");
> @@ -140,8 +140,10 @@ static int nx_test3(fwts_framework *fw)
>   		return FWTS_ERROR;
>   	}
>
> -	for (i=0; i<n; i++) {
> +	for (i = 0; i < n; i++) {
> +		fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
>   		uint64_t val;
> +
>   		if ((fwts_nx_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
>   			fwts_log_error(fw, "Cannot get CPU info");
>   			return FWTS_ERROR;
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
Keng-Yu Lin Jan. 20, 2015, 6:57 a.m. UTC | #2
On Wed, Jan 14, 2015 at 3:04 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> cppcheck is picking up some minor style issues which can
> be easily fixed:
>
> [src/cpu/nx/nx.c:80]:
>         (style) The scope of the variable 'fwts_nx_cpuinfo' can be reduced.
> [src/cpu/nx/nx.c:133]:
>         (style) The scope of the variable 'fwts_nx_cpuinfo' can be reduced.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/cpu/nx/nx.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/src/cpu/nx/nx.c b/src/cpu/nx/nx.c
> index f2fb4ed..4bdcb55 100644
> --- a/src/cpu/nx/nx.c
> +++ b/src/cpu/nx/nx.c
> @@ -77,7 +77,6 @@ static int nx_test1(fwts_framework *fw)
>
>  static int nx_test2(fwts_framework *fw)
>  {
> -       fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
>         int i;
>         int n;
>         int cpu0_has_nx = 0;
> @@ -98,7 +97,9 @@ static int nx_test2(fwts_framework *fw)
>                 return FWTS_OK;
>         }
>
> -       for (i=0; i<n; i++) {
> +       for (i = 0; i < n; i++) {
> +               fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
> +
>                 if ((fwts_nx_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
>                         fwts_failed(fw, LOG_LEVEL_MEDIUM, "NXCPUInfoRead", "Cannot get CPU%d info", i);
>                         fwts_cpu_free_info(fwts_nx_cpuinfo);
> @@ -130,7 +131,6 @@ static int nx_test3(fwts_framework *fw)
>         int failed = 0;
>         uint64_t msr_value = 0;
>         const uint64_t nx_bit = 1ULL << 34;
> -       fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
>
>         fwts_log_info(fw,
>                 "This test verifies that all CPUs have the same NX flag setting by examining the per CPU MSR register 0x1a0.");
> @@ -140,8 +140,10 @@ static int nx_test3(fwts_framework *fw)
>                 return FWTS_ERROR;
>         }
>
> -       for (i=0; i<n; i++) {
> +       for (i = 0; i < n; i++) {
> +               fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
>                 uint64_t val;
> +
>                 if ((fwts_nx_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
>                         fwts_log_error(fw, "Cannot get CPU info");
>                         return FWTS_ERROR;
> --
> 2.1.4
>
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
diff mbox

Patch

diff --git a/src/cpu/nx/nx.c b/src/cpu/nx/nx.c
index f2fb4ed..4bdcb55 100644
--- a/src/cpu/nx/nx.c
+++ b/src/cpu/nx/nx.c
@@ -77,7 +77,6 @@  static int nx_test1(fwts_framework *fw)
 
 static int nx_test2(fwts_framework *fw)
 {
-	fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
 	int i;
 	int n;
 	int cpu0_has_nx = 0;
@@ -98,7 +97,9 @@  static int nx_test2(fwts_framework *fw)
 		return FWTS_OK;
 	}
 
-	for (i=0; i<n; i++) {
+	for (i = 0; i < n; i++) {
+		fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
+
 		if ((fwts_nx_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
 			fwts_failed(fw, LOG_LEVEL_MEDIUM, "NXCPUInfoRead", "Cannot get CPU%d info", i);
 			fwts_cpu_free_info(fwts_nx_cpuinfo);
@@ -130,7 +131,6 @@  static int nx_test3(fwts_framework *fw)
 	int failed = 0;
 	uint64_t msr_value = 0;
 	const uint64_t nx_bit = 1ULL << 34;
-	fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
 
 	fwts_log_info(fw,
 		"This test verifies that all CPUs have the same NX flag setting by examining the per CPU MSR register 0x1a0.");
@@ -140,8 +140,10 @@  static int nx_test3(fwts_framework *fw)
 		return FWTS_ERROR;
 	}
 
-	for (i=0; i<n; i++) {
+	for (i = 0; i < n; i++) {
+		fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
 		uint64_t val;
+
 		if ((fwts_nx_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
 			fwts_log_error(fw, "Cannot get CPU info");
 			return FWTS_ERROR;