lkml.org 
[lkml]   [2015]   [Jun]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC/PATCH 4/8] lib/kobject.c: Use strreplace
On Thu, Jun 04, 2015 at 11:37:11AM +0200, Rasmus Villemoes wrote:
> There's probably not many slashes in kobj->name, but starting over
> when we see one feels wrong.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> lib/kobject.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/lib/kobject.c b/lib/kobject.c
> index 3b841b97fccd..597d962d3d4d 100644
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -258,7 +258,6 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
> va_list vargs)
> {
> const char *old_name = kobj->name;
> - char *s;
>
> if (kobj->name && !fmt)
> return 0;
> @@ -270,8 +269,7 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
> }
>
> /* ewww... some of these buggers have '/' in the name ... */
> - while ((s = strchr(kobj->name, '/')))
> - s[0] = '!';
> + strreplace((char *)kobj->name, '/', '!');

Again, I'd rather do
s = kvasprintf(GFP_KERNEL, fmt, vargs);
if (!s)
return -ENOMEM;
strreplace(s, '/', '!');
old_name = kobj->name;
kobj->name = s;
kfree(old_name);


\
 
 \ /
  Last update: 2015-06-05 01:01    [W:0.070 / U:0.796 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site