[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230322141206.56347-3-andriy.shevchenko@linux.intel.com>
Date: Wed, 22 Mar 2023 16:12:05 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Kees Cook <keescook@...omium.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Cezary Rojewski <cezary.rojewski@...el.com>,
linux-ext4@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: "Theodore Ts'o" <tytso@....edu>, Jan Kara <jack@...e.com>,
Andy Shevchenko <andy@...nel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>
Subject: [PATCH v1 2/3] lib/string_helpers: Change returned value of the strreplace()
It's more useful to return the original string 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@...ux.intel.com>
---
include/linux/string.h | 2 +-
lib/string_helpers.c | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index a7bff7ed3cb0..cb0c24ce0826 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -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);
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 230020a2e076..ab7b1577cbcf 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -979,14 +979,18 @@ 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 original string @str.
*/
-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;
--
2.40.0.1.gaa8946217a0b
Powered by blists - more mailing lists