Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1560855 > unrolled thread

[PATCH 03/13] x86/microcode/AMD: Clean up find_equiv_id()

Started byBorislav Petkov <bp@alien8.de>
First post2017-01-17 18:50 +0100
Last post2017-01-18 00:20 +0100
Articles 5 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 03/13] x86/microcode/AMD: Clean up find_equiv_id() Borislav Petkov <bp@alien8.de> - 2017-01-17 18:50 +0100
    Re: [PATCH 03/13] x86/microcode/AMD: Clean up find_equiv_id() Thomas Gleixner <tglx@linutronix.de> - 2017-01-17 19:00 +0100
      Re: [PATCH 03/13] x86/microcode/AMD: Clean up find_equiv_id() Borislav Petkov <bp@alien8.de> - 2017-01-17 19:50 +0100
        Re: [PATCH 03/13] x86/microcode/AMD: Clean up find_equiv_id() Thomas Gleixner <tglx@linutronix.de> - 2017-01-17 20:10 +0100
          Re: [PATCH 03/13] x86/microcode/AMD: Clean up find_equiv_id() Borislav Petkov <bp@alien8.de> - 2017-01-18 00:20 +0100

#1560855 — [PATCH 03/13] x86/microcode/AMD: Clean up find_equiv_id()

FromBorislav Petkov <bp@alien8.de>
Date2017-01-17 18:50 +0100
Subject[PATCH 03/13] x86/microcode/AMD: Clean up find_equiv_id()
Message-ID<t0G3o-1zz-25@gated-at.bofh.it>
From: Borislav Petkov <bp@suse.de>

No need to have it marked "inline" - let gcc decide. Also, shorten the
argument name and simplify while-test.

No functionality change.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/cpu/microcode/amd.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 3f89e6712afe..889fd61bc033 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -97,17 +97,16 @@ static size_t compute_container_size(u8 *data, u32 total_size)
 	return size;
 }
 
-static inline u16 find_equiv_id(struct equiv_cpu_entry *equiv_cpu_table,
-				unsigned int sig)
+static u16 find_equiv_id(struct equiv_cpu_entry *equiv_table, u32 sig)
 {
 	int i = 0;
 
-	if (!equiv_cpu_table)
+	if (!equiv_table)
 		return 0;
 
-	while (equiv_cpu_table[i].installed_cpu != 0) {
-		if (sig == equiv_cpu_table[i].installed_cpu)
-			return equiv_cpu_table[i].equiv_cpu;
+	while (equiv_table[i].installed_cpu) {
+		if (sig == equiv_table[i].installed_cpu)
+			return equiv_table[i].equiv_cpu;
 
 		i++;
 	}
-- 
2.11.0

[toc] | [next] | [standalone]


#1560874

FromThomas Gleixner <tglx@linutronix.de>
Date2017-01-17 19:00 +0100
Message-ID<t0Gd4-1D8-33@gated-at.bofh.it>
In reply to#1560855
On Tue, 17 Jan 2017, Borislav Petkov wrote:

> From: Borislav Petkov <bp@suse.de>
> 
> No need to have it marked "inline" - let gcc decide. Also, shorten the
> argument name and simplify while-test.
> 
> No functionality change.
> 
> Signed-off-by: Borislav Petkov <bp@suse.de>
> ---
>  arch/x86/kernel/cpu/microcode/amd.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
> index 3f89e6712afe..889fd61bc033 100644
> --- a/arch/x86/kernel/cpu/microcode/amd.c
> +++ b/arch/x86/kernel/cpu/microcode/amd.c
> @@ -97,17 +97,16 @@ static size_t compute_container_size(u8 *data, u32 total_size)
>  	return size;
>  }
>  
> -static inline u16 find_equiv_id(struct equiv_cpu_entry *equiv_cpu_table,
> -				unsigned int sig)
> +static u16 find_equiv_id(struct equiv_cpu_entry *equiv_table, u32 sig)
>  {
>  	int i = 0;
>  
> -	if (!equiv_cpu_table)
> +	if (!equiv_table)
>  		return 0;
>  
> -	while (equiv_cpu_table[i].installed_cpu != 0) {
> -		if (sig == equiv_cpu_table[i].installed_cpu)
> -			return equiv_cpu_table[i].equiv_cpu;
> +	while (equiv_table[i].installed_cpu) {
> +		if (sig == equiv_table[i].installed_cpu)
> +			return equiv_table[i].equiv_cpu;
>  
>  		i++;

While you are at it, please rewrite that thing as a for loop, which is the
obvious correct thing:

	for (i = 0; equiv_table[i].installed_cpu; i++)

and even simpler:

	for (; equiv_table->installed_cpu; equiv_table++)
	
Hmm?

Thanks,

	tglx

[toc] | [prev] | [next] | [standalone]


#1560916

FromBorislav Petkov <bp@alien8.de>
Date2017-01-17 19:50 +0100
Message-ID<t0GZr-295-13@gated-at.bofh.it>
In reply to#1560874
On Tue, Jan 17, 2017 at 06:54:48PM +0100, Thomas Gleixner wrote:
> and even simpler:
> 
> 	for (; equiv_table->installed_cpu; equiv_table++)

Very nice, thanks!

Here's v1.1:

---
From: Borislav Petkov <bp@suse.de>
Date: Sun, 18 Dec 2016 12:05:50 +0100
Subject: [PATCH -v1.1 03/13] x86/microcode/AMD: Clean up find_equiv_id()

No need to have it marked "inline" - let gcc decide. Also, shorten the
argument name and simplify while-test.

While at it, make it into a proper for-loop and simplify it even more,
as tglx suggests.

No functionality change.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/cpu/microcode/amd.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 3f89e6712afe..142fb9950e2a 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -97,20 +97,12 @@ static size_t compute_container_size(u8 *data, u32 total_size)
 	return size;
 }
 
-static inline u16 find_equiv_id(struct equiv_cpu_entry *equiv_cpu_table,
-				unsigned int sig)
+static u16 find_equiv_id(struct equiv_cpu_entry *equiv_table, u32 sig)
 {
-	int i = 0;
-
-	if (!equiv_cpu_table)
-		return 0;
+	for (; equiv_table && equiv_table->installed_cpu; equiv_table++)
+		if (sig == equiv_table->installed_cpu)
+			return equiv_table->equiv_cpu;
 
-	while (equiv_cpu_table[i].installed_cpu != 0) {
-		if (sig == equiv_cpu_table[i].installed_cpu)
-			return equiv_cpu_table[i].equiv_cpu;
-
-		i++;
-	}
 	return 0;
 }
 
-- 
2.11.0

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

[toc] | [prev] | [next] | [standalone]


#1560941

FromThomas Gleixner <tglx@linutronix.de>
Date2017-01-17 20:10 +0100
Message-ID<t0HiO-2uu-31@gated-at.bofh.it>
In reply to#1560916
On Tue, 17 Jan 2017, Borislav Petkov wrote:
> +	for (; equiv_table && equiv_table->installed_cpu; equiv_table++)
> +		if (sig == equiv_table->installed_cpu)
> +			return equiv_table->equiv_cpu;

This would be perfect if you just kept the braces around the for loop.

	for (; cond; incr)
		do_something();

parses perfectly fine as it matches the expectation of a single line statement
following the for().

	for (; cond; incr)
		if (othercond)
			do_something();

not so much because we expect a single line statement due to the lack of a
opening brace after the for()

	for (; cond; incr) {
		if (othercond)
			do_something();
	}

That's how it parses best. The opening brace after the for() tells us: here
comes a multiline statement. And the inner if (othercond) w/o the opening
brace tells: here comes a single line statement.

Reading code/patches very much depends on patterns and structuring. If they
are consistent the reading flow is undisturbed.

Thanks,

	tglx

[toc] | [prev] | [next] | [standalone]


#1561097

FromBorislav Petkov <bp@alien8.de>
Date2017-01-18 00:20 +0100
Message-ID<t0LcL-4RA-31@gated-at.bofh.it>
In reply to#1560941
On Tue, Jan 17, 2017 at 08:02:59PM +0100, Thomas Gleixner wrote:
> That's how it parses best. The opening brace after the for() tells us: here
> comes a multiline statement. And the inner if (othercond) w/o the opening
> brace tells: here comes a single line statement.
> 
> Reading code/patches very much depends on patterns and structuring. If they
> are consistent the reading flow is undisturbed.

Yeah, very true.

---
From: Borislav Petkov <bp@suse.de>
Date: Sun, 18 Dec 2016 12:05:50 +0100
Subject: [PATCH] x86/microcode/AMD: Clean up find_equiv_id()

No need to have it marked "inline" - let gcc decide. Also, shorten the
argument name and simplify while-test.

While at it, make it into a proper for-loop and simplify it even more,
as tglx suggests.

No functionality change.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/cpu/microcode/amd.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 6a31e2691f3a..5c1509a38048 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -97,20 +97,13 @@ static size_t compute_container_size(u8 *data, u32 total_size)
 	return size;
 }
 
-static inline u16 find_equiv_id(struct equiv_cpu_entry *equiv_cpu_table,
-				unsigned int sig)
+static u16 find_equiv_id(struct equiv_cpu_entry *equiv_table, u32 sig)
 {
-	int i = 0;
-
-	if (!equiv_cpu_table)
-		return 0;
-
-	while (equiv_cpu_table[i].installed_cpu != 0) {
-		if (sig == equiv_cpu_table[i].installed_cpu)
-			return equiv_cpu_table[i].equiv_cpu;
-
-		i++;
+	for (; equiv_table && equiv_table->installed_cpu; equiv_table++) {
+		if (sig == equiv_table->installed_cpu)
+			return equiv_table->equiv_cpu;
 	}
+
 	return 0;
 }
 
-- 
2.11.0

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web