Skip to content

Commit d01a77a

Browse files
andy-shevkees
authored andcommitted
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 <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7afb6d8 commit d01a77a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

include/linux/string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
169169
#endif
170170

171171
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);
173173

174174
extern void kfree_const(const void *x);
175175

lib/string_helpers.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,18 +979,22 @@ EXPORT_SYMBOL(__sysfs_match_string);
979979

980980
/**
981981
* strreplace - Replace all occurrences of character in string.
982-
* @s: The string to operate on.
982+
* @str: The string to operate on.
983983
* @old: The character being replaced.
984984
* @new: The character @old is replaced with.
985985
*
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.
987989
*/
988-
char *strreplace(char *s, char old, char new)
990+
char *strreplace(char *str, char old, char new)
989991
{
992+
char *s = str;
993+
990994
for (; *s; ++s)
991995
if (*s == old)
992996
*s = new;
993-
return s;
997+
return str;
994998
}
995999
EXPORT_SYMBOL(strreplace);
9961000

0 commit comments

Comments
 (0)