Skip to content

Commit e001bba

Browse files
author
Russell King
committed
ARM: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
A recent change in kernel/acct.c added a new warning for many configurations on ARM: kernel/acct.c: In function 'acct_pin_kill': arch/arm/include/asm/cmpxchg.h:122:3: warning: value computed is not used [-Wunused-value] 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 ARM 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: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 31cd08c commit e001bba

1 file changed

Lines changed: 37 additions & 29 deletions

File tree

‎arch/arm/include/asm/cmpxchg.h‎

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
103103
return ret;
104104
}
105105

106-
#define xchg(ptr,x) \
107-
((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
106+
#define xchg(ptr, x) ({ \
107+
(__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), \
108+
sizeof(*(ptr))); \
109+
})
108110

109111
#include <asm-generic/cmpxchg-local.h>
110112

@@ -119,14 +121,16 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
119121
* cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
120122
* them available.
121123
*/
122-
#define cmpxchg_local(ptr, o, n) \
123-
((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
124-
(unsigned long)(n), sizeof(*(ptr))))
124+
#define cmpxchg_local(ptr, o, n) ({ \
125+
(__typeof(*ptr))__cmpxchg_local_generic((ptr), \
126+
(unsigned long)(o), \
127+
(unsigned long)(n), \
128+
sizeof(*(ptr))); \
129+
})
130+
125131
#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
126132

127-
#ifndef CONFIG_SMP
128133
#include <asm-generic/cmpxchg.h>
129-
#endif
130134

131135
#else /* min ARCH >= ARMv6 */
132136

@@ -202,11 +206,12 @@ static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
202206
return ret;
203207
}
204208

205-
#define cmpxchg(ptr,o,n) \
206-
((__typeof__(*(ptr)))__cmpxchg_mb((ptr), \
207-
(unsigned long)(o), \
208-
(unsigned long)(n), \
209-
sizeof(*(ptr))))
209+
#define cmpxchg(ptr,o,n) ({ \
210+
(__typeof__(*(ptr)))__cmpxchg_mb((ptr), \
211+
(unsigned long)(o), \
212+
(unsigned long)(n), \
213+
sizeof(*(ptr))); \
214+
})
210215

211216
static inline unsigned long __cmpxchg_local(volatile void *ptr,
212217
unsigned long old,
@@ -228,6 +233,13 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr,
228233
return ret;
229234
}
230235

236+
#define cmpxchg_local(ptr, o, n) ({ \
237+
(__typeof(*ptr))__cmpxchg_local((ptr), \
238+
(unsigned long)(o), \
239+
(unsigned long)(n), \
240+
sizeof(*(ptr))); \
241+
})
242+
231243
static inline unsigned long long __cmpxchg64(unsigned long long *ptr,
232244
unsigned long long old,
233245
unsigned long long new)
@@ -253,6 +265,14 @@ static inline unsigned long long __cmpxchg64(unsigned long long *ptr,
253265
return oldval;
254266
}
255267

268+
#define cmpxchg64_relaxed(ptr, o, n) ({ \
269+
(__typeof__(*(ptr)))__cmpxchg64((ptr), \
270+
(unsigned long long)(o), \
271+
(unsigned long long)(n)); \
272+
})
273+
274+
#define cmpxchg64_local(ptr, o, n) cmpxchg64_relaxed((ptr), (o), (n))
275+
256276
static inline unsigned long long __cmpxchg64_mb(unsigned long long *ptr,
257277
unsigned long long old,
258278
unsigned long long new)
@@ -266,23 +286,11 @@ static inline unsigned long long __cmpxchg64_mb(unsigned long long *ptr,
266286
return ret;
267287
}
268288

269-
#define cmpxchg_local(ptr,o,n) \
270-
((__typeof__(*(ptr)))__cmpxchg_local((ptr), \
271-
(unsigned long)(o), \
272-
(unsigned long)(n), \
273-
sizeof(*(ptr))))
274-
275-
#define cmpxchg64(ptr, o, n) \
276-
((__typeof__(*(ptr)))__cmpxchg64_mb((ptr), \
277-
(unsigned long long)(o), \
278-
(unsigned long long)(n)))
279-
280-
#define cmpxchg64_relaxed(ptr, o, n) \
281-
((__typeof__(*(ptr)))__cmpxchg64((ptr), \
282-
(unsigned long long)(o), \
283-
(unsigned long long)(n)))
284-
285-
#define cmpxchg64_local(ptr, o, n) cmpxchg64_relaxed((ptr), (o), (n))
289+
#define cmpxchg64(ptr, o, n) ({ \
290+
(__typeof__(*(ptr)))__cmpxchg64_mb((ptr), \
291+
(unsigned long long)(o), \
292+
(unsigned long long)(n)); \
293+
})
286294

287295
#endif /* __LINUX_ARM_ARCH__ >= 6 */
288296

0 commit comments

Comments
 (0)