Lines Matching refs:kobj
30 static int populate_dir(struct kobject *kobj) in populate_dir() argument
32 struct kobj_type *t = get_ktype(kobj); in populate_dir()
39 error = sysfs_create_file(kobj, attr); in populate_dir()
47 static int create_dir(struct kobject *kobj) in create_dir() argument
50 if (kobject_name(kobj)) { in create_dir()
51 error = sysfs_create_dir(kobj); in create_dir()
53 error = populate_dir(kobj); in create_dir()
55 sysfs_remove_dir(kobj); in create_dir()
61 static int get_kobj_path_length(struct kobject *kobj) in get_kobj_path_length() argument
64 struct kobject *parent = kobj; in get_kobj_path_length()
79 static void fill_kobj_path(struct kobject *kobj, char *path, int length) in fill_kobj_path() argument
84 for (parent = kobj; parent; parent = parent->parent) { in fill_kobj_path()
92 pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj), in fill_kobj_path()
93 kobj, __func__, path); in fill_kobj_path()
104 char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask) in kobject_get_path() argument
109 len = get_kobj_path_length(kobj); in kobject_get_path()
115 fill_kobj_path(kobj, path, len); in kobject_get_path()
122 static void kobj_kset_join(struct kobject *kobj) in kobj_kset_join() argument
124 if (!kobj->kset) in kobj_kset_join()
127 kset_get(kobj->kset); in kobj_kset_join()
128 spin_lock(&kobj->kset->list_lock); in kobj_kset_join()
129 list_add_tail(&kobj->entry, &kobj->kset->list); in kobj_kset_join()
130 spin_unlock(&kobj->kset->list_lock); in kobj_kset_join()
134 static void kobj_kset_leave(struct kobject *kobj) in kobj_kset_leave() argument
136 if (!kobj->kset) in kobj_kset_leave()
139 spin_lock(&kobj->kset->list_lock); in kobj_kset_leave()
140 list_del_init(&kobj->entry); in kobj_kset_leave()
141 spin_unlock(&kobj->kset->list_lock); in kobj_kset_leave()
142 kset_put(kobj->kset); in kobj_kset_leave()
145 static void kobject_init_internal(struct kobject *kobj) in kobject_init_internal() argument
147 if (!kobj) in kobject_init_internal()
149 kref_init(&kobj->kref); in kobject_init_internal()
150 INIT_LIST_HEAD(&kobj->entry); in kobject_init_internal()
151 kobj->state_in_sysfs = 0; in kobject_init_internal()
152 kobj->state_add_uevent_sent = 0; in kobject_init_internal()
153 kobj->state_remove_uevent_sent = 0; in kobject_init_internal()
154 kobj->state_initialized = 1; in kobject_init_internal()
158 static int kobject_add_internal(struct kobject *kobj) in kobject_add_internal() argument
163 if (!kobj) in kobject_add_internal()
166 if (!kobj->name || !kobj->name[0]) { in kobject_add_internal()
168 "name!\n", kobj); in kobject_add_internal()
172 parent = kobject_get(kobj->parent); in kobject_add_internal()
175 if (kobj->kset) { in kobject_add_internal()
177 parent = kobject_get(&kobj->kset->kobj); in kobject_add_internal()
178 kobj_kset_join(kobj); in kobject_add_internal()
179 kobj->parent = parent; in kobject_add_internal()
183 kobject_name(kobj), kobj, __func__, in kobject_add_internal()
185 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>"); in kobject_add_internal()
187 error = create_dir(kobj); in kobject_add_internal()
189 kobj_kset_leave(kobj); in kobject_add_internal()
191 kobj->parent = NULL; in kobject_add_internal()
198 __func__, kobject_name(kobj)); in kobject_add_internal()
201 __func__, kobject_name(kobj), error, in kobject_add_internal()
204 kobj->state_in_sysfs = 1; in kobject_add_internal()
215 int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, in kobject_set_name_vargs() argument
218 const char *old_name = kobj->name; in kobject_set_name_vargs()
221 if (kobj->name && !fmt) in kobject_set_name_vargs()
224 kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs); in kobject_set_name_vargs()
225 if (!kobj->name) in kobject_set_name_vargs()
229 while ((s = strchr(kobj->name, '/'))) in kobject_set_name_vargs()
245 int kobject_set_name(struct kobject *kobj, const char *fmt, ...) in kobject_set_name() argument
251 retval = kobject_set_name_vargs(kobj, fmt, vargs); in kobject_set_name()
270 void kobject_init(struct kobject *kobj, struct kobj_type *ktype) in kobject_init() argument
274 if (!kobj) { in kobject_init()
282 if (kobj->state_initialized) { in kobject_init()
285 "object, something is seriously wrong.\n", kobj); in kobject_init()
289 kobject_init_internal(kobj); in kobject_init()
290 kobj->ktype = ktype; in kobject_init()
294 printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str); in kobject_init()
299 static int kobject_add_varg(struct kobject *kobj, struct kobject *parent, in kobject_add_varg() argument
304 retval = kobject_set_name_vargs(kobj, fmt, vargs); in kobject_add_varg()
309 kobj->parent = parent; in kobject_add_varg()
310 return kobject_add_internal(kobj); in kobject_add_varg()
338 int kobject_add(struct kobject *kobj, struct kobject *parent, in kobject_add() argument
344 if (!kobj) in kobject_add()
347 if (!kobj->state_initialized) { in kobject_add()
350 kobject_name(kobj), kobj); in kobject_add()
355 retval = kobject_add_varg(kobj, parent, fmt, args); in kobject_add()
373 int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, in kobject_init_and_add() argument
379 kobject_init(kobj, ktype); in kobject_init_and_add()
382 retval = kobject_add_varg(kobj, parent, fmt, args); in kobject_init_and_add()
399 int kobject_rename(struct kobject *kobj, const char *new_name) in kobject_rename() argument
407 kobj = kobject_get(kobj); in kobject_rename()
408 if (!kobj) in kobject_rename()
410 if (!kobj->parent) in kobject_rename()
413 devpath = kobject_get_path(kobj, GFP_KERNEL); in kobject_rename()
433 error = sysfs_rename_dir(kobj, new_name); in kobject_rename()
438 dup_name = kobj->name; in kobject_rename()
439 kobj->name = name; in kobject_rename()
444 kobject_uevent_env(kobj, KOBJ_MOVE, envp); in kobject_rename()
450 kobject_put(kobj); in kobject_rename()
461 int kobject_move(struct kobject *kobj, struct kobject *new_parent) in kobject_move() argument
469 kobj = kobject_get(kobj); in kobject_move()
470 if (!kobj) in kobject_move()
474 if (kobj->kset) in kobject_move()
475 new_parent = kobject_get(&kobj->kset->kobj); in kobject_move()
478 devpath = kobject_get_path(kobj, GFP_KERNEL); in kobject_move()
491 error = sysfs_move_dir(kobj, new_parent); in kobject_move()
494 old_parent = kobj->parent; in kobject_move()
495 kobj->parent = new_parent; in kobject_move()
498 kobject_uevent_env(kobj, KOBJ_MOVE, envp); in kobject_move()
501 kobject_put(kobj); in kobject_move()
511 void kobject_del(struct kobject *kobj) in kobject_del() argument
513 if (!kobj) in kobject_del()
516 sysfs_remove_dir(kobj); in kobject_del()
517 kobj->state_in_sysfs = 0; in kobject_del()
518 kobj_kset_leave(kobj); in kobject_del()
519 kobject_put(kobj->parent); in kobject_del()
520 kobj->parent = NULL; in kobject_del()
527 struct kobject *kobject_get(struct kobject *kobj) in kobject_get() argument
529 if (kobj) in kobject_get()
530 kref_get(&kobj->kref); in kobject_get()
531 return kobj; in kobject_get()
534 static struct kobject *kobject_get_unless_zero(struct kobject *kobj) in kobject_get_unless_zero() argument
536 if (!kref_get_unless_zero(&kobj->kref)) in kobject_get_unless_zero()
537 kobj = NULL; in kobject_get_unless_zero()
538 return kobj; in kobject_get_unless_zero()
545 static void kobject_cleanup(struct kobject *kobj) in kobject_cleanup() argument
547 struct kobj_type *t = get_ktype(kobj); in kobject_cleanup()
548 const char *name = kobj->name; in kobject_cleanup()
551 kobject_name(kobj), kobj, __func__); in kobject_cleanup()
556 kobject_name(kobj), kobj); in kobject_cleanup()
559 if (kobj->state_add_uevent_sent && !kobj->state_remove_uevent_sent) { in kobject_cleanup()
561 kobject_name(kobj), kobj); in kobject_cleanup()
562 kobject_uevent(kobj, KOBJ_REMOVE); in kobject_cleanup()
566 if (kobj->state_in_sysfs) { in kobject_cleanup()
568 kobject_name(kobj), kobj); in kobject_cleanup()
569 kobject_del(kobj); in kobject_cleanup()
574 kobject_name(kobj), kobj); in kobject_cleanup()
575 t->release(kobj); in kobject_cleanup()
596 void kobject_put(struct kobject *kobj) in kobject_put() argument
598 if (kobj) { in kobject_put()
599 if (!kobj->state_initialized) in kobject_put()
602 "called.\n", kobject_name(kobj), kobj); in kobject_put()
603 kref_put(&kobj->kref, kobject_release); in kobject_put()
607 static void dynamic_kobj_release(struct kobject *kobj) in dynamic_kobj_release() argument
609 pr_debug("kobject: (%p): %s\n", kobj, __func__); in dynamic_kobj_release()
610 kfree(kobj); in dynamic_kobj_release()
631 struct kobject *kobj; in kobject_create() local
633 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); in kobject_create()
634 if (!kobj) in kobject_create()
637 kobject_init(kobj, &dynamic_kobj_ktype); in kobject_create()
638 return kobj; in kobject_create()
656 struct kobject *kobj; in kobject_create_and_add() local
659 kobj = kobject_create(); in kobject_create_and_add()
660 if (!kobj) in kobject_create_and_add()
663 retval = kobject_add(kobj, parent, "%s", name); in kobject_create_and_add()
667 kobject_put(kobj); in kobject_create_and_add()
668 kobj = NULL; in kobject_create_and_add()
670 return kobj; in kobject_create_and_add()
680 kobject_init_internal(&k->kobj); in kset_init()
686 static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr, in kobj_attr_show() argument
694 ret = kattr->show(kobj, kattr, buf); in kobj_attr_show()
698 static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr, in kobj_attr_store() argument
706 ret = kattr->store(kobj, kattr, buf, count); in kobj_attr_store()
727 err = kobject_add_internal(&k->kobj); in kset_register()
730 kobject_uevent(&k->kobj, KOBJ_ADD); in kset_register()
742 kobject_put(&k->kobj); in kset_unregister()
772 static void kset_release(struct kobject *kobj) in kset_release() argument
774 struct kset *kset = container_of(kobj, struct kset, kobj); in kset_release()
776 kobject_name(kobj), kobj, __func__); in kset_release()
810 retval = kobject_set_name(&kset->kobj, name); in kset_create()
816 kset->kobj.parent = parent_kobj; in kset_create()
823 kset->kobj.ktype = &kset_ktype; in kset_create()
824 kset->kobj.kset = NULL; in kset_create()
915 const struct kobj_ns_type_operations *kobj_ns_ops(struct kobject *kobj) in kobj_ns_ops() argument
917 return kobj_child_ns_ops(kobj->parent); in kobj_ns_ops()