diff mbox series

[v2,3/3] kobject: Use return value of strreplace()

Message ID 20230323123704.37983-4-andriy.shevchenko@linux.intel.com
State Not Applicable
Headers show
Series lib/string_helpers et al.: Change return value of strreplace() | expand

Commit Message

Andy Shevchenko March 23, 2023, 12:37 p.m. UTC
Since strreplace() returns the pointer to the string itself,
we may use it directly in the code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/kobject.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

David Laight March 26, 2023, 1:37 p.m. UTC | #1
From: Andy Shevchenko
> Sent: 23 March 2023 12:37
>
> Since strreplace() returns the pointer to the string itself,
> we may use it directly in the code.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  lib/kobject.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/lib/kobject.c b/lib/kobject.c
> index f79a434e1231..16d530f9c174 100644
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -281,8 +281,7 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
>  		kfree_const(s);
>  		if (!t)
>  			return -ENOMEM;
> -		strreplace(t, '/', '!');
> -		s = t;
> +		s = strreplace(t, '/', '!');

Why do this? It just makes the code harder to read because
you have to know another 'silly fact' about a function.

Possibly useful return values might be:
1) The address of the first changed character.
2) The address of the last changed characher.
3) The '\0' terminator.
4) void.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
diff mbox series

Patch

diff --git a/lib/kobject.c b/lib/kobject.c
index f79a434e1231..16d530f9c174 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -281,8 +281,7 @@  int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
 		kfree_const(s);
 		if (!t)
 			return -ENOMEM;
-		strreplace(t, '/', '!');
-		s = t;
+		s = strreplace(t, '/', '!');
 	}
 	kfree_const(kobj->name);
 	kobj->name = s;