From b05118226cb05198ea454dfc119276709e02dea0 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 29 Nov 2007 18:32:47 -0500 Subject: [PATCH] --- yaml --- r: 75725 b: refs/heads/master c: 663a47430b361f863b515752a97166a7a4b92d35 h: refs/heads/master i: 75723: 9d5e0b88ae6a8e85bcb72704ee17666809b89603 v: v3 --- [refs] | 2 +- trunk/lib/kobject.c | 71 ++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/[refs] b/[refs] index f04c0845a482..588d08605ed1 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 15f2bbb28e96e20149548926e5b08551ba140b14 +refs/heads/master: 663a47430b361f863b515752a97166a7a4b92d35 diff --git a/trunk/lib/kobject.c b/trunk/lib/kobject.c index 9500339ae024..4a310e55a886 100644 --- a/trunk/lib/kobject.c +++ b/trunk/lib/kobject.c @@ -232,60 +232,53 @@ int kobject_register(struct kobject * kobj) return error; } +/** + * kobject_set_name_vargs - Set the name of an kobject + * @kobj: struct kobject to set the name of + * @fmt: format string used to build the name + * @vargs: vargs to format the string. + */ +static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, + va_list vargs) +{ + va_list aq; + char *name; + + va_copy(aq, vargs); + name = kvasprintf(GFP_KERNEL, fmt, vargs); + va_end(aq); + + if (!name) + return -ENOMEM; + + /* Free the old name, if necessary. */ + kfree(kobj->k_name); + + /* Now, set the new name */ + kobj->k_name = name; + + return 0; +} /** * kobject_set_name - Set the name of a kobject - * @kobj: kobject to name + * @kobj: struct kobject to set the name of * @fmt: format string used to build the name * * This sets the name of the kobject. If you have already added the * kobject to the system, you must call kobject_rename() in order to * change the name of the kobject. */ -int kobject_set_name(struct kobject * kobj, const char * fmt, ...) +int kobject_set_name(struct kobject *kobj, const char *fmt, ...) { - int error = 0; - int limit; - int need; va_list args; - char *name; + int retval; - /* find out how big a buffer we need */ - name = kmalloc(1024, GFP_KERNEL); - if (!name) { - error = -ENOMEM; - goto done; - } va_start(args, fmt); - need = vsnprintf(name, 1024, fmt, args); + retval = kobject_set_name_vargs(kobj, fmt, args); va_end(args); - kfree(name); - /* Allocate the new space and copy the string in */ - limit = need + 1; - name = kmalloc(limit, GFP_KERNEL); - if (!name) { - error = -ENOMEM; - goto done; - } - va_start(args, fmt); - need = vsnprintf(name, limit, fmt, args); - va_end(args); - - /* something wrong with the string we copied? */ - if (need >= limit) { - kfree(name); - error = -EFAULT; - goto done; - } - - /* Free the old name, if necessary. */ - kfree(kobj->k_name); - - /* Now, set the new name */ - kobj->k_name = name; -done: - return error; + return retval; } EXPORT_SYMBOL(kobject_set_name);