To support performance benchmarking in KUnit tests, extract the generic C implementation of strrchr() into a standalone function __generic_strrchr(). This allows tests to compare architecture-optimized versions against the generic baseline without duplicating code.
Suggested-by: Andy Shevchenko <[email protected]> Signed-off-by: Feng Jiang <[email protected]> --- include/linux/string.h | 1 + lib/string.c | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/linux/string.h b/include/linux/string.h index 57f8bf543891..2ede3ff0865a 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -180,6 +180,7 @@ extern char * strnchrnul(const char *, size_t, int); #ifndef __HAVE_ARCH_STRNCHR extern char * strnchr(const char *, size_t, int); #endif +extern char *__generic_strrchr(const char *, int); #ifndef __HAVE_ARCH_STRRCHR extern char * strrchr(const char *,int); #endif diff --git a/lib/string.c b/lib/string.c index 8ad9b73ffe4e..4405a042eee7 100644 --- a/lib/string.c +++ b/lib/string.c @@ -377,6 +377,18 @@ char *strnchrnul(const char *s, size_t count, int c) return (char *)s; } +char *__generic_strrchr(const char *s, int c) +{ + const char *last = NULL; + + do { + if (*s == (char)c) + last = s; + } while (*s++); + return (char *)last; +} +EXPORT_SYMBOL(__generic_strrchr); + #ifndef __HAVE_ARCH_STRRCHR /** * strrchr - Find the last occurrence of a character in a string @@ -385,12 +397,7 @@ char *strnchrnul(const char *s, size_t count, int c) */ char *strrchr(const char *s, int c) { - const char *last = NULL; - do { - if (*s == (char)c) - last = s; - } while (*s++); - return (char *)last; + return __generic_strrchr(s, c); } EXPORT_SYMBOL(strrchr); #endif -- 2.25.1
