From: Mateusz Guzik <mjguzik@gmail.com>
To: tglx@linutronix.de, bp@alien8.de, andy@kernel.org,
akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
Mateusz Guzik <mjguzik@gmail.com>
Subject: [PATCH 2/2] string: retire bcmp()
Date: Sat, 23 Nov 2024 10:47:29 +0100 [thread overview]
Message-ID: <20241123094729.1099378-3-mjguzik@gmail.com> (raw)
In-Reply-To: <20241123094729.1099378-1-mjguzik@gmail.com>
While architectures could override it thanks to __HAVE_ARCH_BCMP, none
of them did. Instead it was implemented as a call to memcmp().
These routines differ in the API contract: memcmp()'s result indicates
which way the difference goes (making it usable for sorting), whereas
bcmp()'s result merely states whether the buffers differ in any way.
This means that a dedicated optimized bcmp() is cheaper to execute than
memcmp() for differing buffers as there is no need to compute the return
value.
However, per the above nobody bothered to write one and it is unclear if
it makes sense to do it.
Users which really want to compare stuff may want to handle it
differently (like e.g., the path lookup).
As there are no users and the code is merely a wrapper around memcmp(),
just whack it.
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
arch/x86/boot/string.c | 8 --------
arch/x86/boot/string.h | 1 -
include/linux/string.h | 3 ---
lib/Makefile | 3 +--
lib/string.c | 19 -------------------
5 files changed, 1 insertion(+), 33 deletions(-)
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index c23f3b9c84fe..e8095abf03df 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -37,14 +37,6 @@ int memcmp(const void *s1, const void *s2, size_t len)
return diff;
}
-/*
- * Clang may lower `memcmp == 0` to `bcmp == 0`.
- */
-int bcmp(const void *s1, const void *s2, size_t len)
-{
- return memcmp(s1, s2, len);
-}
-
int strcmp(const char *str1, const char *str2)
{
const unsigned char *s1 = (const unsigned char *)str1;
diff --git a/arch/x86/boot/string.h b/arch/x86/boot/string.h
index e5d2c6b8c2f1..cf83faee78cc 100644
--- a/arch/x86/boot/string.h
+++ b/arch/x86/boot/string.h
@@ -11,7 +11,6 @@ void *memcpy(void *dst, const void *src, size_t len);
void *memmove(void *dst, const void *src, size_t len);
void *memset(void *dst, int c, size_t len);
int memcmp(const void *s1, const void *s2, size_t len);
-int bcmp(const void *s1, const void *s2, size_t len);
/* Access builtin version by default. */
#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
diff --git a/include/linux/string.h b/include/linux/string.h
index 0dd27afcfaf7..d4904951b627 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -267,9 +267,6 @@ extern void * memscan(void *,int,__kernel_size_t);
#ifndef __HAVE_ARCH_MEMCMP
extern int memcmp(const void *,const void *,__kernel_size_t);
#endif
-#ifndef __HAVE_ARCH_BCMP
-extern int bcmp(const void *,const void *,__kernel_size_t);
-#endif
#ifndef __HAVE_ARCH_MEMCHR
extern void * memchr(const void *,int,__kernel_size_t);
#endif
diff --git a/lib/Makefile b/lib/Makefile
index 773adf88af41..c382b43fe37e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -265,8 +265,7 @@ obj-$(CONFIG_IRQ_POLL) += irq_poll.o
obj-$(CONFIG_POLYNOMIAL) += polynomial.o
# stackdepot.c should not be instrumented or call instrumented functions.
-# Prevent the compiler from calling builtins like memcmp() or bcmp() from this
-# file.
+# Prevent the compiler from calling builtins like memcmp() from this file.
CFLAGS_stackdepot.o += -fno-builtin
obj-$(CONFIG_STACKDEPOT) += stackdepot.o
KASAN_SANITIZE_stackdepot.o := n
diff --git a/lib/string.c b/lib/string.c
index 76327b51e36f..3a319d1c5aae 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -680,25 +680,6 @@ __visible int memcmp(const void *cs, const void *ct, size_t count)
EXPORT_SYMBOL(memcmp);
#endif
-#ifndef __HAVE_ARCH_BCMP
-/**
- * bcmp - returns 0 if and only if the buffers have identical contents.
- * @a: pointer to first buffer.
- * @b: pointer to second buffer.
- * @len: size of buffers.
- *
- * The sign or magnitude of a non-zero return value has no particular
- * meaning, and architectures may implement their own more efficient bcmp(). So
- * while this particular implementation is a simple (tail) call to memcmp, do
- * not rely on anything but whether the return value is zero or non-zero.
- */
-int bcmp(const void *a, const void *b, size_t len)
-{
- return memcmp(a, b, len);
-}
-EXPORT_SYMBOL(bcmp);
-#endif
-
#ifndef __HAVE_ARCH_MEMSCAN
/**
* memscan - Find a character in an area of memory.
--
2.43.0
next prev parent reply other threads:[~2024-11-23 9:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-23 9:47 [PATCH 0/2] retire bcmp, a redundant wrapper around memcmp Mateusz Guzik
2024-11-23 9:47 ` [PATCH 1/2] x86/callthunks: s/bcmp/memcmp/ Mateusz Guzik
2024-11-23 9:47 ` Mateusz Guzik [this message]
2024-11-23 15:13 ` [PATCH 2/2] string: retire bcmp() David Laight
2024-11-23 18:31 ` Andy Shevchenko
2024-11-23 19:09 ` Nathan Chancellor
2024-11-23 19:15 ` Mateusz Guzik
2024-11-25 9:02 ` kernel test robot
2024-11-25 11:42 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241123094729.1099378-3-mjguzik@gmail.com \
--to=mjguzik@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox