diff options
Diffstat (limited to 'lib/kobject.c')
-rw-r--r-- | lib/kobject.c | 42 |
1 files changed, 42 insertions, 0 deletions
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, ...) | |||
283 | EXPORT_SYMBOL(kobject_set_name); | 283 | EXPORT_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 | */ | ||
297 | void 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 | |||
321 | error: | ||
322 | printk(KERN_ERR "kobject: %s\n", err_str); | ||
323 | dump_stack(); | ||
324 | } | ||
325 | EXPORT_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 |