summaryrefslogtreecommitdiff
path: root/lib/kobject.c
diff options
context:
space:
mode:
authorPatrick Mochel <mochel@osdl.org>2003-01-05 23:56:06 -0600
committerPatrick Mochel <mochel@osdl.org>2003-01-05 23:56:06 -0600
commit85e865ecdb545bdd8b650540563528c1d3f6e9af (patch)
treeee72feaa12b6296c7587c08f013f6fe4fd4f3d53 /lib/kobject.c
parent3e815107666d4ee5089661a7125af302797b3e08 (diff)
kobjects: Remove kobject::subsys and subsystem::kobj.
The kobject core no longer references a subsystem directly through a kobject, instead using the kobject's dominant kset to reference the subsystem. The registrants of kobjects have been fixed up. To aid in this process, a few helpers were introdcuced: - kobj_set_kset_s(obj,subsys) - kset_set_kset_s(obj,subsys) - subsys_set_kset(obj,subsys) that set the kset ptr of embedded kobjects for objects that have different embedded types. See include/linux/kobject.h for more description and usage. struct subsystem::kobj is also removed, relying solely on a subsystem's embedded kset for hierarchy information. Since this requires modification of the subsystem declarations, a helper macro has been defined: decl_subsys(name,type) which initializes the name and ktype fields of the subsystem's embedded kset. All the subsystem declarations have been fixed up.
Diffstat (limited to 'lib/kobject.c')
-rw-r--r--lib/kobject.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 3d414df3683e..59872973992a 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -11,6 +11,14 @@
static spinlock_t kobj_lock = SPIN_LOCK_UNLOCKED;
+static inline struct kobj_type * get_ktype(struct kobject * k)
+{
+ if (k->kset && k->kset->ktype)
+ return k->kset->ktype;
+ else
+ return k->ktype;
+}
+
/**
* populate_dir - populate directory with attributes.
* @kobj: object we're working on.
@@ -25,7 +33,7 @@ static spinlock_t kobj_lock = SPIN_LOCK_UNLOCKED;
static int populate_dir(struct kobject * kobj)
{
- struct kobj_type * t = kobj->ktype;
+ struct kobj_type * t = get_ktype(kobj);
struct attribute * attr;
int error = 0;
int i;
@@ -84,11 +92,6 @@ int kobject_add(struct kobject * kobj)
kobj->name, parent ? parent->name : "<NULL>",
kobj->kset ? kobj->kset->kobj.name : "<NULL>" );
- if (kobj->subsys) {
- if (!kobj->kset)
- kobj->kset = &kobj->subsys->kset;
- }
-
if (kobj->kset) {
down_write(&kobj->kset->subsys->rwsem);
if (parent)
@@ -177,7 +180,7 @@ struct kobject * kobject_get(struct kobject * kobj)
void kobject_cleanup(struct kobject * kobj)
{
- struct kobj_type * t = kobj->ktype;
+ struct kobj_type * t = get_ktype(kobj);
struct kset * s = kobj->kset;
pr_debug("kobject %s: cleaning up\n",kobj->name);
@@ -263,7 +266,6 @@ void kset_unregister(struct kset * k)
void subsystem_init(struct subsystem * s)
{
- memcpy(&s->kset.kobj,&s->kobj,sizeof(struct kobject));
init_rwsem(&s->rwsem);
kset_init(&s->kset);
}
@@ -308,7 +310,7 @@ int subsys_create_file(struct subsystem * s, struct subsys_attribute * a)
{
int error = 0;
if (subsys_get(s)) {
- error = sysfs_create_file(&s->kobj,&a->attr);
+ error = sysfs_create_file(&s->kset.kobj,&a->attr);
subsys_put(s);
}
return error;
@@ -324,7 +326,7 @@ int subsys_create_file(struct subsystem * s, struct subsys_attribute * a)
void subsys_remove_file(struct subsystem * s, struct subsys_attribute * a)
{
if (subsys_get(s)) {
- sysfs_remove_file(&s->kobj,&a->attr);
+ sysfs_remove_file(&s->kset.kobj,&a->attr);
subsys_put(s);
}
}