[PATCH] powerpc: use swap() to make code cleaner

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE1762d

4 messages, 3 authors, 2021-11-04 · open the first message on its own page

[PATCH] powerpc: use swap() to make code cleaner

From: <hidden>
Date: 2021-11-04 06:17:24

From: Yang Guang <redacted>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
opencoding it.

Reported-by: Zeal Robot <redacted>
Signed-off-by: Yang Guang <redacted>
---
 arch/powerpc/kernel/fadump.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index b7ceb041743c..5b40e2d46090 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -1265,7 +1265,6 @@ static void fadump_release_reserved_area(u64 start, u64 end)
 static void sort_and_merge_mem_ranges(struct fadump_mrange_info *mrange_info)
 {
 	struct fadump_memory_range *mem_ranges;
-	struct fadump_memory_range tmp_range;
 	u64 base, size;
 	int i, j, idx;
 
@@ -1281,9 +1280,7 @@ static void sort_and_merge_mem_ranges(struct fadump_mrange_info *mrange_info)
 				idx = j;
 		}
 		if (idx != i) {
-			tmp_range = mem_ranges[idx];
-			mem_ranges[idx] = mem_ranges[i];
-			mem_ranges[i] = tmp_range;
+			swap(mem_ranges[idx], mem_ranges[i]);
 		}
 	}
 
-- 
2.30.2

Re: [PATCH] powerpc: use swap() to make code cleaner

From: Stephen Rothwell <hidden>
Date: 2021-11-04 10:07:10

Hi,

On Thu,  4 Nov 2021 14:17:09 +0800 davidcomponentone@gmail.com wrote:
From: Yang Guang <redacted>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
opencoding it.
So if swap() is in the above include file, then you should include it.

-- 
Cheers,
Stephen Rothwell

Re: [PATCH] powerpc: use swap() to make code cleaner

From: Segher Boessenkool <hidden>
Date: 2021-11-04 11:40:27

On Thu, Nov 04, 2021 at 09:06:56PM +1100, Stephen Rothwell wrote:
On Thu,  4 Nov 2021 14:17:09 +0800 davidcomponentone@gmail.com wrote:
quoted
From: Yang Guang <redacted>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
opencoding it.
So if swap() is in the above include file, then you should include it.
It is included from kernel.h already (which is included from delay.h).


Segher

Re: [PATCH] powerpc: use swap() to make code cleaner

From: Stephen Rothwell <hidden>
Date: 2021-11-04 20:26:27

Hi Segher,

On Thu, 4 Nov 2021 06:33:51 -0500 Segher Boessenkool [off-list ref] wrote:
On Thu, Nov 04, 2021 at 09:06:56PM +1100, Stephen Rothwell wrote:
quoted
On Thu,  4 Nov 2021 14:17:09 +0800 davidcomponentone@gmail.com wrote:  
quoted
From: Yang Guang <redacted>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
opencoding it.  
So if swap() is in the above include file, then you should include it.  
It is included from kernel.h already (which is included from delay.h).
And that becomes a pain when include files get "cleaned up". :-(

$ grep kernel.h include/linux/delay.h
$

See commit

  300424acf349 ("include/linux/delay.h: replace kernel.h with the necessary inclusions")

currently pending the Andrew Morton's patch queue (the above is a
linux-next commit).
-- 
Cheers,
Stephen Rothwell
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help