diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2023-06-05 20:05:52 +0300 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2023-06-05 15:31:12 -0700 |
commit | d01a77afd6bef1b3a2ed15e8ca6887ca7da0cddc (patch) | |
tree | ff135babefe273e172313fe59590cdd79ac512c1 /lib/string_helpers.c | |
parent | 7afb6d8fa81fd8d332f70ead5e35d8c90abb8165 (diff) |
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
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r-- | lib/string_helpers.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 230020a2e076..d3b1dd718daf 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -979,18 +979,22 @@ EXPORT_SYMBOL(__sysfs_match_string); /** * strreplace - Replace all occurrences of character in string. - * @s: The string to operate on. + * @str: The string to operate on. * @old: The character being replaced. * @new: The character @old is replaced with. * - * Returns pointer to the nul byte at the end of @s. + * Replaces the each @old character with a @new one in the given string @str. + * + * Return: pointer to the string @str itself. */ -char *strreplace(char *s, char old, char new) +char *strreplace(char *str, char old, char new) { + char *s = str; + for (; *s; ++s) if (*s == old) *s = new; - return s; + return str; } EXPORT_SYMBOL(strreplace); |