Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/string_helpers: Change returned value of the strreplace()

It's more useful to return the pointer to the string itself
with strreplace(), so it may be used like

attr->name = strreplace(name, '/', '_');

While at it, amend the kernel documentation.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230605170553.7835-3-andriy.shevchenko@linux.intel.com

authored by

Andy Shevchenko and committed by
Kees Cook
d01a77af 7afb6d8f

+9 -5
+1 -1
include/linux/string.h
··· 169 169 #endif 170 170 171 171 void *memchr_inv(const void *s, int c, size_t n); 172 - char *strreplace(char *s, char old, char new); 172 + char *strreplace(char *str, char old, char new); 173 173 174 174 extern void kfree_const(const void *x); 175 175
+8 -4
lib/string_helpers.c
··· 979 979 980 980 /** 981 981 * strreplace - Replace all occurrences of character in string. 982 - * @s: The string to operate on. 982 + * @str: The string to operate on. 983 983 * @old: The character being replaced. 984 984 * @new: The character @old is replaced with. 985 985 * 986 - * Returns pointer to the nul byte at the end of @s. 986 + * Replaces the each @old character with a @new one in the given string @str. 987 + * 988 + * Return: pointer to the string @str itself. 987 989 */ 988 - char *strreplace(char *s, char old, char new) 990 + char *strreplace(char *str, char old, char new) 989 991 { 992 + char *s = str; 993 + 990 994 for (; *s; ++s) 991 995 if (*s == old) 992 996 *s = new; 993 - return s; 997 + return str; 994 998 } 995 999 EXPORT_SYMBOL(strreplace); 996 1000