lkml.org 
[lkml]   [2015]   [Jun]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 4/8] lib/kobject.c: Use strreplace
Date
There's probably not many slashes in the name, but starting over when
we see one feels wrong.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
v2: Original code relied on the const laundering done by strchr; v1
had a corresponding explicit (char*) cast. Avoid this altogether.

lib/kobject.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 3b841b97fccd..75ee63834fd1 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -257,23 +257,20 @@ static int kobject_add_internal(struct kobject *kobj)
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;

- kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
- if (!kobj->name) {
- kobj->name = old_name;
+ s = kvasprintf(GFP_KERNEL, fmt, vargs);
+ if (!s)
return -ENOMEM;
- }

/* ewww... some of these buggers have '/' in the name ... */
- while ((s = strchr(kobj->name, '/')))
- s[0] = '!';
+ strreplace(s, '/', '!');
+ kfree(kobj->name);
+ kobj->name = s;

- kfree(old_name);
return 0;
}

--
2.1.3


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