From 210fedfcfc1a146faac67dddb3581c6b9dcd01b4 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Wed, 8 Jul 2026 22:37:03 +0200 Subject: string: correct prototype of strchrnul() Both glibc's (where this originated as a GNU extension) and the kernel's versions of strchrnul() return "char *", not "const char *". That also makes it consistent with the standard strchr() function. Reviewed-by: Simon Glass Signed-off-by: Rasmus Villemoes --- include/linux/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/string.h b/include/linux/string.h index 850356d7c3f..488a459ed99 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -63,7 +63,7 @@ extern char * strchr(const char *,int); * @c: character to search for * Return: position of @c in @s, or end of @s if not found */ -const char *strchrnul(const char *s, int c); +char *strchrnul(const char *s, int c); #ifndef __HAVE_ARCH_STRRCHR extern char * strrchr(const char *,int); -- cgit v1.3.1 From a31d9375dfbd7f0f4030c0b81f2030ff554529be Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Wed, 8 Jul 2026 22:37:05 +0200 Subject: string: remove unused strswab() function The last use of this function with rather peculiar semantics[*] vanished in 2021 with 0a527fda782 ("Fix IDE commands issued, fix endian issues, fix non MMIO"). It has no tests, and should a need for something similar ever appear, it is better done with some proper utf16le/utf16be/utf16 abstractions rather than cluttering code with '#ifdef __LITTLE_ENDIAN'. [*] The byte-swapping itself is weird enough. But why is an input string of odd length ok, while the empty string is not allowed? Reviewed-by: Simon Glass Signed-off-by: Rasmus Villemoes --- include/linux/string.h | 4 ---- lib/string.c | 28 ---------------------------- 2 files changed, 32 deletions(-) (limited to 'include') diff --git a/include/linux/string.h b/include/linux/string.h index 488a459ed99..5bcbf72a89b 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -107,10 +107,6 @@ extern char * strndup(const char *, size_t); extern const char *strdup_const(const char *s); extern void kfree_const(const void *x); -#ifndef __HAVE_ARCH_STRSWAB -extern char * strswab(const char *); -#endif - #ifndef __HAVE_ARCH_MEMSET extern void * memset(void *,int,__kernel_size_t); #endif diff --git a/lib/string.c b/lib/string.c index 45f0f5f8d09..82d0b6a9caa 100644 --- a/lib/string.c +++ b/lib/string.c @@ -503,34 +503,6 @@ char * strsep(char **s, const char *ct) } #endif -#ifndef __HAVE_ARCH_STRSWAB -/** - * strswab - swap adjacent even and odd bytes in %NUL-terminated string - * s: address of the string - * - * returns the address of the swapped string or NULL on error. If - * string length is odd, last byte is untouched. - */ -char *strswab(const char *s) -{ - char *p, *q; - - if ((NULL == s) || ('\0' == *s)) { - return (NULL); - } - - for (p=(char *)s, q=p+1; (*p != '\0') && (*q != '\0'); p+=2, q+=2) { - char tmp; - - tmp = *p; - *p = *q; - *q = tmp; - } - - return (char *) s; -} -#endif - #ifndef __HAVE_ARCH_MEMSET /** * memset - Fill a region of memory with the given value -- cgit v1.3.1 From 07fcb18623b4d4ad604668cfccb63890ce300ce5 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Wed, 8 Jul 2026 22:37:06 +0200 Subject: string: remove more pointless __HAVE_ARCH_STR* None of these six macros are defined by any architecture. Moreover, the ifndef guard only exists in either string.h or string.c, making them completely pointless. I'm not sure whether we have an explicit coding style discouraging the "extern" qualifier on function declarations, and string.h has a random mix of everything, but I can't leave it on strncasecmp() now that it will be immediately after strcasecmp() which doesn't have it. Reviewed-by: Simon Glass Signed-off-by: Rasmus Villemoes --- include/linux/string.h | 6 +----- lib/string.c | 8 -------- 2 files changed, 1 insertion(+), 13 deletions(-) (limited to 'include') diff --git a/include/linux/string.h b/include/linux/string.h index 5bcbf72a89b..5e4594b19df 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -43,12 +43,8 @@ extern int strcmp(const char *,const char *); #ifndef __HAVE_ARCH_STRNCMP extern int strncmp(const char *,const char *,__kernel_size_t); #endif -#ifndef __HAVE_ARCH_STRCASECMP int strcasecmp(const char *s1, const char *s2); -#endif -#ifndef __HAVE_ARCH_STRNCASECMP -extern int strncasecmp(const char *s1, const char *s2, __kernel_size_t len); -#endif +int strncasecmp(const char *s1, const char *s2, __kernel_size_t len); #ifndef __HAVE_ARCH_STRCHR extern char * strchr(const char *,int); #endif diff --git a/lib/string.c b/lib/string.c index 82d0b6a9caa..20c934c18c3 100644 --- a/lib/string.c +++ b/lib/string.c @@ -399,7 +399,6 @@ void kfree_const(const void *x) } -#ifndef __HAVE_ARCH_STRSPN /** * strspn - Calculate the length of the initial substring of @s which only * contain letters in @accept @@ -424,9 +423,7 @@ size_t strspn(const char *s, const char *accept) return count; } -#endif -#ifndef __HAVE_ARCH_STRPBRK /** * strpbrk - Find the first occurrence of a set of characters * @cs: The string to be searched @@ -444,9 +441,7 @@ char * strpbrk(const char * cs,const char * ct) } return NULL; } -#endif -#ifndef __HAVE_ARCH_STRTOK /** * strtok - Split a string into tokens * @s: The string to be searched @@ -473,9 +468,7 @@ char * strtok(char * s,const char * ct) ___strtok = send; return (sbegin); } -#endif -#ifndef __HAVE_ARCH_STRSEP /** * strsep - Split a string into tokens * @s: The string to be searched @@ -501,7 +494,6 @@ char * strsep(char **s, const char *ct) return sbegin; } -#endif #ifndef __HAVE_ARCH_MEMSET /** -- cgit v1.3.1 From 13822d7f42706da356368f1389f8de10ac9869a5 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Wed, 8 Jul 2026 22:37:07 +0200 Subject: string: add strcasestr() While this is not likely needed by any "real" driver code, a later convenience addition to the "config" command will need this. As usual, the linker will throw it away if nothing actually uses it, so it should have no size impact when not used. Reviewed-by: Simon Glass Signed-off-by: Rasmus Villemoes --- include/linux/string.h | 1 + lib/string.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'include') diff --git a/include/linux/string.h b/include/linux/string.h index 5e4594b19df..986499dfc70 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -71,6 +71,7 @@ extern char * strstr(const char *,const char *); #ifndef __HAVE_ARCH_STRNSTR extern char *strnstr(const char *, const char *, size_t); #endif +char *strcasestr(const char *, const char *); #ifndef __HAVE_ARCH_STRLEN extern __kernel_size_t strlen(const char *); #endif diff --git a/lib/string.c b/lib/string.c index 20c934c18c3..dbf2ce340df 100644 --- a/lib/string.c +++ b/lib/string.c @@ -701,6 +701,33 @@ char *strstr(const char *s1, const char *s2) } #endif +/** + * strcasestr() - Case insensitive substring search + * + * @haystack: string to be searched + * @needle: string to search for + * + * Return: pointer to the first occurrence or NULL + * + * The case of both strings are ignored. + */ +char *strcasestr(const char *haystack, const char *needle) +{ + size_t l1, l2; + + l1 = strlen(haystack); + l2 = strlen(needle); + + while (l1 >= l2) { + if (!strncasecmp(haystack, needle, l2)) + return (char *)haystack; + haystack++; + l1--; + } + + return NULL; +} + #ifndef __HAVE_ARCH_MEMCHR /** * memchr - Find a character in an area of memory. -- cgit v1.3.1