From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Kees Cook <keescook@chromium.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Cezary Rojewski <cezary.rojewski@intel.com>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Theodore Ts'o" <tytso@mit.edu>, Jan Kara <jack@suse.com>,
Andy Shevchenko <andy@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>
Subject: [PATCH v2 2/3] lib/string_helpers: Change returned value of the strreplace()
Date: Thu, 23 Mar 2023 14:37:03 +0200 [thread overview]
Message-ID: <20230323123704.37983-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230323123704.37983-1-andriy.shevchenko@linux.intel.com>
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>
---
include/linux/string.h | 2 +-
lib/string_helpers.c | 12 ++++++++----
2 files changed, 9 insertions(+), 5 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..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);
--
2.40.0.1.gaa8946217a0b
next prev parent reply other threads:[~2023-03-23 12:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-23 12:37 [PATCH v2 0/3] lib/string_helpers et al.: Change return value of strreplace() Andy Shevchenko
2023-03-23 12:37 ` [PATCH v2 1/3] jbd2: Avoid printing outside the boundary of the buffer Andy Shevchenko
2023-03-23 12:37 ` Andy Shevchenko [this message]
2023-03-23 12:37 ` [PATCH v2 3/3] kobject: Use return value of strreplace() Andy Shevchenko
2023-03-26 13:37 ` David Laight
2023-04-05 13:34 ` [PATCH v2 0/3] lib/string_helpers et al.: Change " Andy Shevchenko
2023-04-05 14:24 ` Greg Kroah-Hartman
2023-04-05 14:38 ` Andy Shevchenko
2023-04-06 2:58 ` Kees Cook
2023-06-05 14:04 ` Andy Shevchenko
2023-06-05 16:57 ` Greg Kroah-Hartman
2023-06-05 17:06 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230323123704.37983-3-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=cezary.rojewski@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jack@suse.com \
--cc=keescook@chromium.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).