[PATCH v2 02/14] lib/string: extract generic strnlen() into __generic_strnlen()
Feng Jiang
jiangfeng at kylinos.cn
Tue Jan 13 00:27:36 PST 2026
To support performance benchmarking in KUnit tests, extract the
generic C implementation of strnlen() into a standalone function
__generic_strnlen(). This allows tests to compare architecture-optimized
versions against the generic baseline without duplicating code.
Suggested-by: Andy Shevchenko <andy at kernel.org>
Signed-off-by: Feng Jiang <jiangfeng at kylinos.cn>
---
include/linux/string.h | 1 +
lib/string.c | 10 ++++++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index 961645633b4d..04b5fef7a4ec 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -201,6 +201,7 @@ extern __kernel_size_t __generic_strlen(const char *);
#ifndef __HAVE_ARCH_STRLEN
extern __kernel_size_t strlen(const char *);
#endif
+extern __kernel_size_t __generic_strnlen(const char *, __kernel_size_t);
#ifndef __HAVE_ARCH_STRNLEN
extern __kernel_size_t strnlen(const char *,__kernel_size_t);
#endif
diff --git a/lib/string.c b/lib/string.c
index 047ecb38e09b..9dfe7177e290 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -430,8 +430,7 @@ size_t strlen(const char *s)
EXPORT_SYMBOL(strlen);
#endif
-#ifndef __HAVE_ARCH_STRNLEN
-size_t strnlen(const char *s, size_t count)
+size_t __generic_strnlen(const char *s, size_t count)
{
const char *sc;
@@ -439,6 +438,13 @@ size_t strnlen(const char *s, size_t count)
/* nothing */;
return sc - s;
}
+EXPORT_SYMBOL(__generic_strnlen);
+
+#ifndef __HAVE_ARCH_STRNLEN
+size_t strnlen(const char *s, size_t count)
+{
+ return __generic_strnlen(s, count);
+}
EXPORT_SYMBOL(strnlen);
#endif
--
2.25.1
More information about the linux-riscv
mailing list