treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / c6x / include / asm / cmpxchg.h
blob6eed628a9e7ff813be5f9aa91ff3c94a69e0ada5
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Port on Texas Instruments TMS320C6x architecture
5 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
6 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7 */
8 #ifndef _ASM_C6X_CMPXCHG_H
9 #define _ASM_C6X_CMPXCHG_H
11 #include <linux/irqflags.h>
14 * Misc. functions
16 static inline unsigned int __xchg(unsigned int x, volatile void *ptr, int size)
18 unsigned int tmp;
19 unsigned long flags;
21 local_irq_save(flags);
23 switch (size) {
24 case 1:
25 tmp = 0;
26 tmp = *((unsigned char *) ptr);
27 *((unsigned char *) ptr) = (unsigned char) x;
28 break;
29 case 2:
30 tmp = 0;
31 tmp = *((unsigned short *) ptr);
32 *((unsigned short *) ptr) = x;
33 break;
34 case 4:
35 tmp = 0;
36 tmp = *((unsigned int *) ptr);
37 *((unsigned int *) ptr) = x;
38 break;
40 local_irq_restore(flags);
41 return tmp;
44 #define xchg(ptr, x) \
45 ((__typeof__(*(ptr)))__xchg((unsigned int)(x), (void *) (ptr), \
46 sizeof(*(ptr))))
48 #include <asm-generic/cmpxchg-local.h>
51 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
52 * them available.
54 #define cmpxchg_local(ptr, o, n) \
55 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), \
56 (unsigned long)(o), \
57 (unsigned long)(n), \
58 sizeof(*(ptr))))
59 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
61 #include <asm-generic/cmpxchg.h>
63 #endif /* _ASM_C6X_CMPXCHG_H */