aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/kobject.h1
-rw-r--r--lib/kobject.c42
2 files changed, 43 insertions, 0 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 2d19a079ee79..bdf4f7c45f19 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -79,6 +79,7 @@ static inline const char * kobject_name(const struct kobject * kobj)
79} 79}
80 80
81extern void kobject_init(struct kobject *); 81extern void kobject_init(struct kobject *);
82extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype);
82extern int __must_check kobject_add(struct kobject *); 83extern int __must_check kobject_add(struct kobject *);
83extern void kobject_del(struct kobject *); 84extern void kobject_del(struct kobject *);
84 85
diff --git a/lib/kobject.c b/lib/kobject.c
index a152036db006..60586bcc7a71 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -283,6 +283,48 @@ int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
283EXPORT_SYMBOL(kobject_set_name); 283EXPORT_SYMBOL(kobject_set_name);
284 284
285/** 285/**
286 * kobject_init_ng - initialize a kobject structure
287 * @kobj: pointer to the kobject to initialize
288 * @ktype: pointer to the ktype for this kobject.
289 *
290 * This function will properly initialize a kobject such that it can then
291 * be passed to the kobject_add() call.
292 *
293 * After this function is called, the kobject MUST be cleaned up by a call
294 * to kobject_put(), not by a call to kfree directly to ensure that all of
295 * the memory is cleaned up properly.
296 */
297void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype)
298{
299 char *err_str;
300
301 if (!kobj) {
302 err_str = "invalid kobject pointer!";
303 goto error;
304 }
305 if (!ktype) {
306 err_str = "must have a ktype to be initialized properly!\n";
307 goto error;
308 }
309 if (atomic_read(&kobj->kref.refcount)) {
310 /* do not error out as sometimes we can recover */
311 printk(KERN_ERR "kobject: reference count is already set, "
312 "something is seriously wrong.\n");
313 dump_stack();
314 }
315
316 kref_init(&kobj->kref);
317 INIT_LIST_HEAD(&kobj->entry);
318 kobj->ktype = ktype;
319 return;
320
321error:
322 printk(KERN_ERR "kobject: %s\n", err_str);
323 dump_stack();
324}
325EXPORT_SYMBOL(kobject_init_ng);
326
327/**
286 * kobject_rename - change the name of an object 328 * kobject_rename - change the name of an object
287 * @kobj: object in question. 329 * @kobj: object in question.
288 * @new_name: object's new name 330 * @new_name: object's new name