[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260113082748.250916-4-jiangfeng@kylinos.cn>
Date: Tue, 13 Jan 2026 16:27:37 +0800
From: Feng Jiang <jiangfeng@...inos.cn>
To: pjw@...nel.org,
palmer@...belt.com,
aou@...s.berkeley.edu,
alex@...ti.fr,
kees@...nel.org,
andy@...nel.org,
akpm@...ux-foundation.org,
jiangfeng@...inos.cn,
ebiggers@...nel.org,
martin.petersen@...cle.com,
ardb@...nel.org,
ajones@...tanamicro.com,
conor.dooley@...rochip.com,
samuel.holland@...ive.com,
linus.walleij@...aro.org,
nathan@...nel.org
Cc: linux-riscv@...ts.infradead.org,
linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: [PATCH v2 03/14] lib/string: extract generic strchr() into __generic_strchr()
To support performance benchmarking in KUnit tests, extract the
generic C implementation of strchr() into a standalone function
__generic_strchr(). This allows tests to compare architecture-optimized
versions against the generic baseline without duplicating code.
Suggested-by: Andy Shevchenko <andy@...nel.org>
Signed-off-by: Feng Jiang <jiangfeng@...inos.cn>
---
include/linux/string.h | 1 +
lib/string.c | 14 ++++++++++----
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index 04b5fef7a4ec..57f8bf543891 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -169,6 +169,7 @@ extern int strcasecmp(const char *s1, const char *s2);
#ifndef __HAVE_ARCH_STRNCASECMP
extern int strncasecmp(const char *s1, const char *s2, size_t n);
#endif
+extern char *__generic_strchr(const char *, int);
#ifndef __HAVE_ARCH_STRCHR
extern char * strchr(const char *,int);
#endif
diff --git a/lib/string.c b/lib/string.c
index 9dfe7177e290..8ad9b73ffe4e 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -317,6 +317,15 @@ int strncmp(const char *cs, const char *ct, size_t count)
EXPORT_SYMBOL(strncmp);
#endif
+char *__generic_strchr(const char *s, int c)
+{
+ for (; *s != (char)c; ++s)
+ if (*s == '\0')
+ return NULL;
+ return (char *)s;
+}
+EXPORT_SYMBOL(__generic_strchr);
+
#ifndef __HAVE_ARCH_STRCHR
/**
* strchr - Find the first occurrence of a character in a string
@@ -328,10 +337,7 @@ EXPORT_SYMBOL(strncmp);
*/
char *strchr(const char *s, int c)
{
- for (; *s != (char)c; ++s)
- if (*s == '\0')
- return NULL;
- return (char *)s;
+ return __generic_strchr(s, c);
}
EXPORT_SYMBOL(strchr);
#endif
--
2.25.1
Powered by blists - more mailing lists