Skip to content

Commit 61eb040

Browse files
tobluxgeertu
authored andcommitted
m68k: cmpxchg: Use swap() to improve code
Remove the local variable tmp and use the swap() macro instead. Signed-off-by: Thorsten Blum <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 8400291 commit 61eb040

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

arch/m68k/include/asm/cmpxchg.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define __ARCH_M68K_CMPXCHG__
44

55
#include <linux/irqflags.h>
6+
#include <linux/minmax.h>
67

78
#define __xg(type, x) ((volatile type *)(x))
89

@@ -11,25 +12,19 @@ extern unsigned long __invalid_xchg_size(unsigned long, volatile void *, int);
1112
#ifndef CONFIG_RMW_INSNS
1213
static inline unsigned long __arch_xchg(unsigned long x, volatile void * ptr, int size)
1314
{
14-
unsigned long flags, tmp;
15+
unsigned long flags;
1516

1617
local_irq_save(flags);
1718

1819
switch (size) {
1920
case 1:
20-
tmp = *(u8 *)ptr;
21-
*(u8 *)ptr = x;
22-
x = tmp;
21+
swap(*(u8 *)ptr, x);
2322
break;
2423
case 2:
25-
tmp = *(u16 *)ptr;
26-
*(u16 *)ptr = x;
27-
x = tmp;
24+
swap(*(u16 *)ptr, x);
2825
break;
2926
case 4:
30-
tmp = *(u32 *)ptr;
31-
*(u32 *)ptr = x;
32-
x = tmp;
27+
swap(*(u32 *)ptr, x);
3328
break;
3429
default:
3530
x = __invalid_xchg_size(x, ptr, size);

0 commit comments

Comments
 (0)