lib/string_helpers: Change returned value of the strreplace()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 5 Jun 2023 17:05:52 +0000 (20:05 +0300)
committerKees Cook <keescook@chromium.org>
Mon, 5 Jun 2023 22:31:12 +0000 (15:31 -0700)
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
include/linux/string.h
lib/string_helpers.c

index c062c581a98b9505990699837ec342c87c2aa808..dbfc66400050f72fb28942ef6eac496542a76372 100644 (file)
@@ -169,7 +169,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
 #endif
 
 void *memchr_inv(const void *s, int c, size_t n);
-char *strreplace(char *s, char old, char new);
+char *strreplace(char *str, char old, char new);
 
 extern void kfree_const(const void *x);
 
index 230020a2e076ce9e14e2a2c960218eac5f6e0134..d3b1dd718dafbd4a46a148cf68089851c8fd64ae 100644 (file)
@@ -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);