[PATCH v8 1/4] x86/asm, x86/boot: expose inline memcmp()
Mauricio Faria de Oliveira <[email protected]>
| Newsgroups | org.xenproject.lists.xen-devel,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Move the inline memcmp function currently only available in 'boot/string.c' into the shared string function header <asm/shared/string.h> to be reused. This is not done through <asm/string.h> to avoid pulling unnecessary code in 'boot/string.c' that causes build errors in 'boot/compressed/string.c' and 'purgatory/purgatory.ro'. Signed-off-by: Mauricio Faria de Oliveira <[email protected]> --- Thanks to David Laight for noticing the return value difference between inline and regular memcmp(). --- arch/x86/boot/string.c | 8 ++------ arch/x86/include/asm/shared/string.h | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index 6827551720dd9b96afe8c55a051401d6cdc6f05e..be454a6864225f3a972c3e81826b77ed4e8a57fe 100644 --- a/arch/x86/boot/string.c +++ b/arch/x86/boot/string.c @@ -15,6 +15,7 @@ #include <linux/errno.h> #include <linux/limits.h> #include <asm/asm.h> +#include <asm/shared/string.h> #include "ctype.h" #include "string.h" @@ -31,12 +32,7 @@ int memcmp(const void *s1, const void *s2, size_t len) { - bool diff; - asm volatile("test %3, %3\n\t" - "repe cmpsb" - : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len) - : : "cc", "memory"); - return diff; + return __inline_memcmp(s1, s2, len); } /* diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/shared/string.h new file mode 100644 index 0000000000000000000000000000000000000000..66a446168fd1e9914b9e00540269f555abe4738d --- /dev/null +++ b/arch/x86/include/asm/shared/string.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_SHARED_STRING_H +#define _ASM_X86_SHARED_STRING_H + +/* + * This inline memcmp() returns 0 (equal) or 1 (not equal). + * The regular memcmp() returns <0 (less than), 0 (equal), or >0 (greater than) + * to indicate ordering as well. + */ +static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len) +{ + bool diff; + + asm volatile("test %3, %3\n\t" + "repe cmpsb" + : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len) + : : "cc", "memory"); + + return diff; +} + +#endif /* _ASM_X86_SHARED_STRING_H */ -- 2.47.3