Skip to content

Commit d975440

Browse files
Marek Vasutarndb
authored andcommitted
asm-generic: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
This change is similar to e001bba ARM: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations A recent change in kernel/acct.c added a new warning for many configurations using generic __xchg() implementation: In file included from ./arch/nios2/include/asm/cmpxchg.h:12:0, from include/asm-generic/atomic.h:18, from arch/nios2/include/generated/asm/atomic.h:1, from include/linux/atomic.h:4, from include/linux/spinlock.h:406, from include/linux/mmzone.h:7, from include/linux/gfp.h:5, from include/linux/mm.h:9, from kernel/acct.c:46: kernel/acct.c: In function 'acct_pin_kill': include/asm-generic/cmpxchg.h:94:3: warning: value computed is not used [-Wunused-value] ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\ ^ include/asm-generic/cmpxchg.h:102:28: note: in expansion of macro 'cmpxchg_local' #define cmpxchg(ptr, o, n) cmpxchg_local((ptr), (o), (n)) ^ kernel/acct.c:177:2: note: in expansion of macro 'cmpxchg' cmpxchg(&acct->ns->bacct, pin, NULL); ^ The code is in fact correct, it's just a cmpxchg() call that intentionally ignores the result, and no other code does that. The warning does not show up on x86 because of the way that its cmpxchg() macro is written. This changes the asm-ggeneric implementation to use a similar construct with a compound expression instead of a typecast, which causes the compiler to not complain about an unused result. Fix the other macros in this file in a similar way, and place them just below their function implementations. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent 16c3bd3 commit d975440

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎include/asm-generic/cmpxchg.h‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
7979
}
8080
}
8181

82-
#define xchg(ptr, x) \
83-
((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
82+
#define xchg(ptr, x) ({ \
83+
((__typeof__(*(ptr))) \
84+
__xchg((unsigned long)(x), (ptr), sizeof(*(ptr)))); \
85+
})
8486

8587
#endif /* xchg */
8688

@@ -90,9 +92,10 @@ unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
9092
#include <asm-generic/cmpxchg-local.h>
9193

9294
#ifndef cmpxchg_local
93-
#define cmpxchg_local(ptr, o, n) \
95+
#define cmpxchg_local(ptr, o, n) ({ \
9496
((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
95-
(unsigned long)(n), sizeof(*(ptr))))
97+
(unsigned long)(n), sizeof(*(ptr)))); \
98+
})
9699
#endif
97100

98101
#ifndef cmpxchg64_local

0 commit comments

Comments
 (0)