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

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <ebiederm@...>, <cornelia.huck@...>, <greg@...>, <stern@...>, <kay.sievers@...>, <linux-kernel@...>, <htejun@...>
Cc: Tejun Heo <htejun@...>
Date: Thursday, September 20, 2007 - 4:05 am

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

Signed-off-by: Tejun Heo <htejun@gmail.com>
---
 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


-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCHSET 3/4] sysfs: divorce sysfs from kobject and dri..., Eric W. Biederman, (Thu Sep 27, 3:25 pm)
Re: [PATCHSET 3/4] sysfs: divorce sysfs from kobject and dri..., Eric W. Biederman, (Wed Oct 10, 9:16 am)
Re: [PATCHSET 3/4] sysfs: divorce sysfs from kobject and dri..., Eric W. Biederman, (Tue Oct 16, 7:54 pm)
Re: [PATCHSET 3/4] sysfs: divorce sysfs from kobject and dri..., Eric W. Biederman, (Wed Oct 10, 5:16 pm)
[PATCH 21/22] sysfs: kill sysfs_hash_and_remove(), Tejun Heo, (Thu Sep 20, 4:05 am)
[PATCH 18/22] kobject: implement __kobject_set_name(), Tejun Heo, (Thu Sep 20, 4:05 am)
[PATCH 05/22] sysfs: implement sysfs_find_child(), Tejun Heo, (Thu Sep 20, 4:05 am)
[PATCH 14/22] sysfs: s/symlink/link/g, Tejun Heo, (Thu Sep 20, 4:05 am)
[PATCH 06/22] sysfs: restructure addrm helpers, Tejun Heo, (Thu Sep 20, 4:05 am)
[PATCH 01/22] sysfs: make sysfs_root a pointer, Tejun Heo, (Thu Sep 20, 4:05 am)
[PATCH 04/22] sysfs: make SYSFS_COPY_NAME a flag, Tejun Heo, (Thu Sep 20, 4:05 am)