*(path + --length) = '/';
}
- pr_debug("%s: path = '%s'\n",__FUNCTION__,path);
+ pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
+ kobj, __FUNCTION__,path);
}
/**
return;
kref_init(&kobj->kref);
INIT_LIST_HEAD(&kobj->entry);
- kobj->kset = kset_get(kobj->kset);
}
* Remove the kobject from the kset list and decrement
* its parent's refcount.
* This is separated out, so we can use it in both
- * kobject_del() and kobject_add() on error.
+ * kobject_del() and kobject_add_internal() on error.
*/
static void unlink(struct kobject * kobj)
{
+ struct kobject *parent = kobj->parent;
+
if (kobj->kset) {
spin_lock(&kobj->kset->list_lock);
list_del_init(&kobj->entry);
spin_unlock(&kobj->kset->list_lock);
}
+ kobj->parent = NULL;
kobject_put(kobj);
+ kobject_put(parent);
}
-/**
- * kobject_add - add an object to the hierarchy.
- * @kobj: object.
- */
-
-int kobject_add(struct kobject * kobj)
+static int kobject_add_internal(struct kobject *kobj)
{
int error = 0;
struct kobject * parent;
if (!kobj->k_name)
kobject_set_name(kobj, "NO_NAME");
if (!*kobj->k_name) {
- pr_debug("kobject attempted to be registered with no name!\n");
+ pr_debug("kobject (%p) attempted to be registered with no "
+ "name!\n", kobj);
WARN_ON(1);
kobject_put(kobj);
return -EINVAL;
}
parent = kobject_get(kobj->parent);
- pr_debug("kobject %s: registering. parent: %s, set: %s\n",
- kobject_name(kobj), parent ? kobject_name(parent) : "<NULL>",
+ pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
+ kobject_name(kobj), kobj, __FUNCTION__,
+ parent ? kobject_name(parent) : "<NULL>",
kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
if (kobj->kset) {
- spin_lock(&kobj->kset->list_lock);
+ kobj->kset = kset_get(kobj->kset);
if (!parent) {
parent = kobject_get(&kobj->kset->kobj);
kobject_get(parent);
}
- list_add_tail(&kobj->entry,&kobj->kset->list);
+ spin_lock(&kobj->kset->list_lock);
+ list_add_tail(&kobj->entry, &kobj->kset->list);
spin_unlock(&kobj->kset->list_lock);
kobj->parent = parent;
}
if (error) {
/* unlink does the kobject_put() for us */
unlink(kobj);
- kobject_put(parent);
/* be noisy on error issues */
if (error == -EEXIST)
- printk(KERN_ERR "kobject_add failed for %s with "
+ printk(KERN_ERR "%s failed for %s with "
"-EEXIST, don't try to register things with "
"the same name in the same directory.\n",
- kobject_name(kobj));
+ __FUNCTION__, kobject_name(kobj));
else
- printk(KERN_ERR "kobject_add failed for %s (%d)\n",
- kobject_name(kobj), error);
+ printk(KERN_ERR "%s failed for %s (%d)\n",
+ __FUNCTION__, kobject_name(kobj), error);
dump_stack();
}
return retval;
}
kobj->parent = parent;
- return kobject_add(kobj);
+ return kobject_add_internal(kobj);
}
/**
- * kobject_add_ng - the main kobject add function
+ * kobject_add - the main kobject add function
* @kobj: the kobject to add
* @parent: pointer to the parent of the kobject.
* @fmt: format to name the kobject with.
* kobject_uevent() with the UEVENT_ADD parameter to ensure that
* userspace is properly notified of this kobject's creation.
*/
-int kobject_add_ng(struct kobject *kobj, struct kobject *parent,
- const char *fmt, ...)
+int kobject_add(struct kobject *kobj, struct kobject *parent,
+ const char *fmt, ...)
{
va_list args;
int retval;
return retval;
}
-EXPORT_SYMBOL(kobject_add_ng);
+EXPORT_SYMBOL(kobject_add);
/**
* kobject_init_and_add - initialize a kobject structure and add it to the kobject hierarchy
* @fmt: the name of the kobject.
*
* This function combines the call to kobject_init_ng() and
- * kobject_add_ng(). The same type of error handling after a call to
- * kobject_add_ng() and kobject lifetime rules are the same here.
+ * kobject_add(). The same type of error handling after a call to
+ * kobject_add() and kobject lifetime rules are the same here.
*/
int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
struct kobject *parent, const char *fmt, ...)
{
if (!kobj)
return;
- pr_debug("kobject %s: unregistering\n",kobject_name(kobj));
+ pr_debug("kobject: '%s' (%p): %s\n",
+ kobject_name(kobj), kobj, __FUNCTION__);
kobject_uevent(kobj, KOBJ_REMOVE);
kobject_del(kobj);
kobject_put(kobj);
{
struct kobj_type * t = get_ktype(kobj);
struct kset * s = kobj->kset;
- struct kobject * parent = kobj->parent;
const char *name = kobj->k_name;
- pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
+ pr_debug("kobject: '%s' (%p): %s\n",
+ kobject_name(kobj), kobj, __FUNCTION__);
if (t && t->release) {
t->release(kobj);
/* If we have a release function, we can guess that this was
}
if (s)
kset_put(s);
- kobject_put(parent);
}
static void kobject_release(struct kref *kref)
static void dynamic_kobj_release(struct kobject *kobj)
{
- pr_debug("%s: freeing %s\n", __FUNCTION__, kobject_name(kobj));
+ pr_debug("kobject: '%s' (%p): %s\n",
+ kobject_name(kobj), kobj, __FUNCTION__);
kfree(kobj);
}
if (!kobj)
return NULL;
- retval = kobject_add_ng(kobj, parent, "%s", name);
+ retval = kobject_add(kobj, parent, "%s", name);
if (retval) {
printk(KERN_WARNING "%s: kobject_add error: %d\n",
__FUNCTION__, retval);
int kset_add(struct kset * k)
{
- return kobject_add(&k->kobj);
+ return kobject_add_internal(&k->kobj);
}
static void kset_release(struct kobject *kobj)
{
struct kset *kset = container_of(kobj, struct kset, kobj);
- pr_debug("kset %s: now freed\n", kobject_name(kobj));
+ pr_debug("kobject: '%s' (%p): %s\n",
+ kobject_name(kobj), kobj, __FUNCTION__);
kfree(kset);
}
EXPORT_SYMBOL(kobject_unregister);
EXPORT_SYMBOL(kobject_get);
EXPORT_SYMBOL(kobject_put);
-EXPORT_SYMBOL(kobject_add);
EXPORT_SYMBOL(kobject_del);
EXPORT_SYMBOL(kset_register);