[PATCH 18/22] kobject: implement __kobject_set_name()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Implement __kobject_set_name() which takes pre-allocated @new_name and
renames the kobject without failing.

Signed-off-by: Tejun Heo <[email protected]>
---
 include/linux/kobject.h |    1 +
 lib/kobject.c           |   13 +++++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index a8a84fc..f7a7734 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -68,6 +68,7 @@ struct kobject {
 	struct sysfs_dirent	* sd;
 };
 
+extern void __kobject_set_name(struct kobject *kobj, const char *new_name);
 extern int kobject_set_name(struct kobject *, const char *, ...)
 	__attribute__((format(printf,2,3)));
 
diff --git a/lib/kobject.c b/lib/kobject.c
index a280c62..1623125 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -230,6 +230,19 @@ int kobject_register(struct kobject * kobj)
 	return error;
 }
 
+/**
+ *	__kobject_set_name - Set the name of an object to preallocated string
+ *	@kobj:		object.
+ *	@new_name:	pointer to pre-allocated string for the new name
+ *
+ *	Set the name of @kobj to @new_name.  @new_name is used
+ *	directly and will be freed using kfree() on @kobj release.
+ */
+void __kobject_set_name(struct kobject *kobj, const char *new_name)
+{
+	kfree(kobj->k_name);
+	kobj->k_name = new_name;
+}
 
 /**
  *	kobject_set_name - Set the name of an object
-- 
1.5.0.3


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux