summaryrefslogtreecommitdiffstats
path: root/arch/mips/include/asm/cmpxchg.h
diff options
context:
space:
mode:
authorPaul Burton <paul.burton@imgtec.com>2017-06-10 02:26:36 +0200
committerRalf Baechle <ralf@linux-mips.org>2017-06-29 02:42:24 +0200
commitd15dc68c1143e249c36612c15bf4e930637b47c3 (patch)
tree3d15ad84f49c8d9735298f4f4915dd7a5e7f69d3 /arch/mips/include/asm/cmpxchg.h
parentMIPS: cmpxchg: Use __compiletime_error() for bad cmpxchg() pointers (diff)
downloadlinux-d15dc68c1143e249c36612c15bf4e930637b47c3.tar.xz
linux-d15dc68c1143e249c36612c15bf4e930637b47c3.zip
MIPS: cmpxchg: Error out on unsupported xchg() calls
xchg() has up until now simply returned the x parameter in cases where it is called with a pointer to a value of an unsupported size. This will often cause the calling code to hit a failure path, presuming that the value of x differs from the content of the memory pointed at by ptr, but we can do better by producing a compile-time or link-time error such that unsupported calls to xchg() are detectable earlier than runtime. This patch does this in the same was as is already done for cmpxchg(), using a call to a missing function annotated with __compiletime_error(). Signed-off-by: Paul Burton <paul.burton@imgtec.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/16351/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/include/asm/cmpxchg.h')
-rw-r--r--arch/mips/include/asm/cmpxchg.h32
1 files changed, 17 insertions, 15 deletions
diff --git a/arch/mips/include/asm/cmpxchg.h b/arch/mips/include/asm/cmpxchg.h
index ee0214e00ab1..fe652c3e5d8c 100644
--- a/arch/mips/include/asm/cmpxchg.h
+++ b/arch/mips/include/asm/cmpxchg.h
@@ -24,6 +24,21 @@
# define __scbeqz "beqz"
#endif
+/*
+ * These functions doesn't exist, so if they are called you'll either:
+ *
+ * - Get an error at compile-time due to __compiletime_error, if supported by
+ * your compiler.
+ *
+ * or:
+ *
+ * - Get an error at link-time due to the call to the missing function.
+ */
+extern void __cmpxchg_called_with_bad_pointer(void)
+ __compiletime_error("Bad argument size for cmpxchg");
+extern unsigned long __xchg_called_with_bad_pointer(void)
+ __compiletime_error("Bad argument size for xchg");
+
#define __xchg_asm(ld, st, m, val) \
({ \
__typeof(*(m)) __ret; \
@@ -89,9 +104,9 @@ static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz
return __xchg_u32(ptr, x);
case 8:
return __xchg_u64(ptr, x);
+ default:
+ return __xchg_called_with_bad_pointer();
}
-
- return x;
}
#define xchg(ptr, x) \
@@ -136,19 +151,6 @@ static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz
__ret; \
})
-/*
- * This function doesn't exist, so if it is called you'll either:
- *
- * - Get an error at compile-time due to __compiletime_error, if supported by
- * your compiler.
- *
- * or:
- *
- * - Get an error at link-time due to the call to the missing function.
- */
-extern void __cmpxchg_called_with_bad_pointer(void)
- __compiletime_error("Bad argument size for cmpxchg");
-
#define __cmpxchg(ptr, old, new, pre_barrier, post_barrier) \
({ \
__typeof__(ptr) __ptr = (ptr); \