On 6/14/05, Greg KH <[email protected]> wrote:
> Heh, yes, sorry, you did.
>
> Hm, I don't even remember why I didn't like it anymore, last I remember,
> I think you got the parent reference counting correct, right? Care to
> dig out the patch and send it again?
I brought this forward from a kernel a couple of months old so it may
need some checking.
diff --git a/drivers/base/class.c b/drivers/base/class.c
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -406,8 +406,9 @@ int class_device_add(struct class_device
/* first, register with generic layer. */
kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id);
- if (parent)
+ if (parent && !class_dev->kobj.parent)
class_dev->kobj.parent = &parent->subsys.kset.kobj;
+ class_dev->kobj.parent = kobject_get(class_dev->kobj.parent);
if ((error = kobject_add(&class_dev->kobj)))
goto register_done;
@@ -438,6 +439,12 @@ int class_device_add(struct class_device
return error;
}
+int class_device_add_child(struct class_device *class_dev, struct
class_device *parent)
+{
+ class_dev->kobj.parent = &class_dev->kobj;
+ return class_device_add(class_dev);
+}
+
int class_device_register(struct class_device *class_dev)
{
class_device_initialize(class_dev);
@@ -463,6 +470,7 @@ void class_device_del(struct class_devic
class_device_remove_attrs(class_dev);
kobject_hotplug(&class_dev->kobj, KOBJ_REMOVE);
+ kobject_put(class_dev->kobj.parent);
kobject_del(&class_dev->kobj);
if (parent)
@@ -581,6 +589,7 @@ EXPORT_SYMBOL_GPL(class_device_register)
EXPORT_SYMBOL_GPL(class_device_unregister);
EXPORT_SYMBOL_GPL(class_device_initialize);
EXPORT_SYMBOL_GPL(class_device_add);
+EXPORT_SYMBOL_GPL(class_device_add_child);
EXPORT_SYMBOL_GPL(class_device_del);
EXPORT_SYMBOL_GPL(class_device_get);
EXPORT_SYMBOL_GPL(class_device_put);
diff --git a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -208,6 +208,7 @@ extern int class_device_register(struct
extern void class_device_unregister(struct class_device *);
extern void class_device_initialize(struct class_device *);
extern int class_device_add(struct class_device *);
+extern int class_device_add_child(struct class_device *, struct
class_device *);
extern void class_device_del(struct class_device *);
extern int class_device_rename(struct class_device *, char *);
--
Jon Smirl
[email protected]
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]