Skip to content

Commit

Permalink
kobject: remove struct kobj_type from struct kset
Browse files Browse the repository at this point in the history
We don't need a "default" ktype for a kset.  We should set this
explicitly every time for each kset.  This change is needed so that we
can make ksets dynamic, and cleans up one of the odd, undocumented
assumption that the kset/kobject/ktype model has.

This patch is based on a lot of help from Kay Sievers.

Nasty bug in the block code was found by Dave Young
<[email protected]>

Cc: Kay Sievers <[email protected]>
Cc: Dave Young <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
gregkh committed Jan 25, 2008
1 parent c11c415 commit 3514fac
Show file tree
Hide file tree
Showing 36 changed files with 84 additions and 87 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/pseries/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static struct subsys_attribute auto_poweron_attr = {
};

#ifndef CONFIG_PM
decl_subsys(power,NULL,NULL);
decl_subsys(power, NULL);

static struct attribute *g[] = {
&auto_poweron_attr.attr,
Expand Down
4 changes: 2 additions & 2 deletions arch/s390/hypfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ static struct super_operations hypfs_s_ops = {
.show_options = hypfs_show_options,
};

static decl_subsys(s390, NULL, NULL);
static decl_subsys(s390, NULL);

static int __init hypfs_init(void)
{
Expand All @@ -506,7 +506,7 @@ static int __init hypfs_init(void)
goto fail_diag;
}
}
kobj_set_kset_s(&s390_subsys, hypervisor_subsys);
s390_subsys.kobj.kset = &hypervisor_subsys;
rc = subsystem_register(&s390_subsys);
if (rc)
goto fail_sysfs;
Expand Down
8 changes: 4 additions & 4 deletions arch/s390/kernel/ipl.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ static struct attribute_group ipl_unknown_attr_group = {
.attrs = ipl_unknown_attrs,
};

static decl_subsys(ipl, NULL, NULL);
static decl_subsys(ipl, NULL);

/*
* reipl section
Expand Down Expand Up @@ -590,7 +590,7 @@ static ssize_t reipl_type_store(struct kset *kset, const char *buf,
static struct subsys_attribute reipl_type_attr =
__ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);

static decl_subsys(reipl, NULL, NULL);
static decl_subsys(reipl, NULL);

/*
* dump section
Expand Down Expand Up @@ -685,13 +685,13 @@ static ssize_t dump_type_store(struct kset *kset, const char *buf,
static struct subsys_attribute dump_type_attr =
__ATTR(dump_type, 0644, dump_type_show, dump_type_store);

static decl_subsys(dump, NULL, NULL);
static decl_subsys(dump, NULL);

/*
* Shutdown actions section
*/

static decl_subsys(shutdown_actions, NULL, NULL);
static decl_subsys(shutdown_actions, NULL);

/* on panic */

Expand Down
5 changes: 3 additions & 2 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ static struct kset_uevent_ops block_uevent_ops = {
.uevent = block_uevent,
};

decl_subsys(block, &ktype_block, &block_uevent_ops);
decl_subsys(block, &block_uevent_ops);

/*
* aggregate disk stat collector. Uses the same stats that the sysfs
Expand Down Expand Up @@ -721,7 +721,8 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
}
}
disk->minors = minors;
kobj_set_kset_s(disk,block_subsys);
disk->kobj.kset = &block_subsys;
disk->kobj.ktype = &ktype_block;
kobject_init(&disk->kobj);
rand_initialize_disk(disk);
INIT_WORK(&disk->async_notify,
Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ static int __init acpi_bus_init(void)
return -ENODEV;
}

decl_subsys(acpi, NULL, NULL);
decl_subsys(acpi, NULL);

static int __init acpi_init(void)
{
Expand Down
5 changes: 3 additions & 2 deletions drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static struct kset_uevent_ops bus_uevent_ops = {
.filter = bus_uevent_filter,
};

static decl_subsys(bus, &bus_ktype, &bus_uevent_ops);
static decl_subsys(bus, &bus_uevent_ops);


#ifdef CONFIG_HOTPLUG
Expand Down Expand Up @@ -639,6 +639,7 @@ int bus_add_driver(struct device_driver *drv)
if (error)
goto out_put_bus;
drv->kobj.kset = &bus->drivers;
drv->kobj.ktype = &driver_ktype;
error = kobject_register(&drv->kobj);
if (error)
goto out_put_bus;
Expand Down Expand Up @@ -851,6 +852,7 @@ int bus_register(struct bus_type * bus)
goto out;

bus->subsys.kobj.kset = &bus_subsys;
bus->subsys.kobj.ktype = &bus_ktype;

retval = subsystem_register(&bus->subsys);
if (retval)
Expand All @@ -868,7 +870,6 @@ int bus_register(struct bus_type * bus)

kobject_set_name(&bus->drivers.kobj, "drivers");
bus->drivers.kobj.parent = &bus->subsys.kobj;
bus->drivers.ktype = &driver_ktype;
retval = kset_register(&bus->drivers);
if (retval)
goto bus_drivers_fail;
Expand Down
8 changes: 5 additions & 3 deletions drivers/base/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static struct kobj_type class_ktype = {
};

/* Hotplug events for classes go to the class_obj subsys */
static decl_subsys(class, &class_ktype, NULL);
static decl_subsys(class, NULL);


int class_create_file(struct class * cls, const struct class_attribute * attr)
Expand Down Expand Up @@ -150,6 +150,7 @@ int class_register(struct class * cls)
return error;

cls->subsys.kobj.kset = &class_subsys;
cls->subsys.kobj.ktype = &class_ktype;

error = subsystem_register(&cls->subsys);
if (!error) {
Expand Down Expand Up @@ -452,7 +453,7 @@ static struct kset_uevent_ops class_uevent_ops = {
.uevent = class_uevent,
};

static decl_subsys(class_obj, &class_device_ktype, &class_uevent_ops);
static decl_subsys(class_obj, &class_uevent_ops);


static int class_device_add_attrs(struct class_device * cd)
Expand Down Expand Up @@ -537,7 +538,8 @@ static struct class_device_attribute class_uevent_attr =

void class_device_initialize(struct class_device *class_dev)
{
kobj_set_kset_s(class_dev, class_obj_subsys);
class_dev->kobj.kset = &class_obj_subsys;
class_dev->kobj.ktype = &class_device_ktype;
kobject_init(&class_dev->kobj);
INIT_LIST_HEAD(&class_dev->node);
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static struct device_attribute devt_attr =
* devices_subsys - structure to be registered with kobject core.
*/

decl_subsys(devices, &device_ktype, &device_uevent_ops);
decl_subsys(devices, &device_uevent_ops);


/**
Expand Down Expand Up @@ -525,7 +525,8 @@ static void klist_children_put(struct klist_node *n)

void device_initialize(struct device *dev)
{
kobj_set_kset_s(dev, devices_subsys);
dev->kobj.kset = &devices_subsys;
dev->kobj.ktype = &device_ktype;
kobject_init(&dev->kobj);
klist_init(&dev->klist_children, klist_children_get,
klist_children_put);
Expand Down
5 changes: 3 additions & 2 deletions drivers/base/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

#include "base.h"

static decl_subsys(firmware, NULL, NULL);
static decl_subsys(firmware, NULL);

int firmware_register(struct kset *s)
{
kobj_set_kset_s(s, firmware_subsys);
s->kobj.kset = &firmware_subsys;
s->kobj.ktype = NULL;
return subsystem_register(s);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/base/hypervisor.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "base.h"

decl_subsys(hypervisor, NULL, NULL);
decl_subsys(hypervisor, NULL);
EXPORT_SYMBOL_GPL(hypervisor_subsys);

int __init hypervisor_init(void)
Expand Down
3 changes: 2 additions & 1 deletion drivers/base/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,15 @@ EXPORT_SYMBOL_GPL(sysdev_class_remove_file);
/*
* declare system_subsys
*/
static decl_subsys(system, &ktype_sysdev_class, NULL);
static decl_subsys(system, NULL);

int sysdev_class_register(struct sysdev_class * cls)
{
pr_debug("Registering sysdev class '%s'\n",
kobject_name(&cls->kset.kobj));
INIT_LIST_HEAD(&cls->drivers);
cls->kset.kobj.parent = &system_subsys.kobj;
cls->kset.kobj.ktype = &ktype_sysdev_class;
cls->kset.kobj.kset = &system_subsys;
return kset_register(&cls->kset);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/edac/edac_mc_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ static struct kobj_type ktype_mc_set_attribs = {
*/
static struct kset mc_kset = {
.kobj = {.ktype = &ktype_mc_set_attribs },
.ktype = &ktype_mci,
};


Expand All @@ -767,6 +766,7 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)

/* this instance become part of the mc_kset */
kobj_mci->kset = &mc_kset;
kobj_mci->ktype = &ktype_mci;

/* set the name of the mc<id> object */
err = kobject_set_name(kobj_mci, "mc%d", mci->mc_idx);
Expand Down
5 changes: 3 additions & 2 deletions drivers/firmware/edd.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ static struct kobj_type edd_ktype = {
.default_attrs = def_attrs,
};

static decl_subsys(edd, &edd_ktype, NULL);
static decl_subsys(edd, NULL);


/**
Expand Down Expand Up @@ -723,7 +723,8 @@ edd_device_register(struct edd_device *edev, int i)
edd_dev_set_info(edev, i);
kobject_set_name(&edev->kobj, "int13_dev%02x",
0x80 + i);
kobj_set_kset_s(edev,edd_subsys);
edev->kobj.kset = &edd_subsys;
edev->kobj.ktype = &edd_ktype;
error = kobject_register(&edev->kobj);
if (!error)
edd_populate_dir(edev);
Expand Down
9 changes: 5 additions & 4 deletions drivers/firmware/efivars.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ static struct subsys_attribute *efi_subsys_attrs[] = {
NULL, /* maybe more in the future? */
};

static decl_subsys(vars, &efivar_ktype, NULL);
static decl_subsys(efi, NULL, NULL);
static decl_subsys(vars, NULL);
static decl_subsys(efi, NULL);

/*
* efivar_create_sysfs_entry()
Expand Down Expand Up @@ -629,7 +629,8 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
efi_guid_unparse(vendor_guid, short_name + strlen(short_name));

kobject_set_name(&new_efivar->kobj, "%s", short_name);
kobj_set_kset_s(new_efivar, vars_subsys);
new_efivar->kobj.kset = &vars_subsys;
new_efivar->kobj.ktype = &efivar_ktype;
i = kobject_register(&new_efivar->kobj);
if (i) {
kfree(short_name);
Expand Down Expand Up @@ -687,7 +688,7 @@ efivars_init(void)
goto out_free;
}

kobj_set_kset_s(&vars_subsys, efi_subsys);
vars_subsys.kobj.kset = &efi_subsys;

error = subsystem_register(&vars_subsys);

Expand Down
9 changes: 5 additions & 4 deletions drivers/parisc/pdc_stable.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,8 @@ static struct subsys_attribute *pdcs_subsys_attrs[] = {
NULL,
};

static decl_subsys(paths, &ktype_pdcspath, NULL);
static decl_subsys(stable, NULL, NULL);
static decl_subsys(paths, NULL);
static decl_subsys(stable, NULL);

/**
* pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
Expand Down Expand Up @@ -997,7 +997,8 @@ pdcs_register_pathentries(void)

if ((err = kobject_set_name(&entry->kobj, "%s", entry->name)))
return err;
kobj_set_kset_s(entry, paths_subsys);
entry->kobj.kset = &paths_subsys;
entry->kobj.ktype = &ktype_pdcspath;
if ((err = kobject_register(&entry->kobj)))
return err;

Expand Down Expand Up @@ -1072,7 +1073,7 @@ pdc_stable_init(void)
error = subsys_create_file(&stable_subsys, attr);

/* register the paths subsys as a subsystem of stable subsys */
kobj_set_kset_s(&paths_subsys, stable_subsys);
paths_subsys.kobj.kset = &stable_subsys;
if ((rc = subsystem_register(&paths_subsys)))
goto fail_subsysreg;

Expand Down
7 changes: 4 additions & 3 deletions drivers/pci/hotplug/pci_hotplug_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static struct kobj_type hotplug_slot_ktype = {
.release = &hotplug_slot_release,
};

decl_subsys_name(pci_hotplug_slots, slots, &hotplug_slot_ktype, NULL);
decl_subsys_name(pci_hotplug_slots, slots, NULL);

/* these strings match up with the values in pci_bus_speed */
static char *pci_bus_speed_strings[] = {
Expand Down Expand Up @@ -633,7 +633,8 @@ int pci_hp_register (struct hotplug_slot *slot)
}

kobject_set_name(&slot->kobj, "%s", slot->name);
kobj_set_kset_s(slot, pci_hotplug_slots_subsys);
slot->kobj.kset = &pci_hotplug_slots_subsys;
slot->kobj.ktype = &hotplug_slot_ktype;

/* this can fail if we have already registered a slot with the same name */
if (kobject_register(&slot->kobj)) {
Expand Down Expand Up @@ -701,7 +702,7 @@ static int __init pci_hotplug_init (void)
{
int result;

kobj_set_kset_s(&pci_hotplug_slots_subsys, pci_bus_type.subsys);
pci_hotplug_slots_subsys.kobj.kset = &pci_bus_type.subsys;
result = subsystem_register(&pci_hotplug_slots_subsys);
if (result) {
err("Register subsys with error %d\n", result);
Expand Down
1 change: 0 additions & 1 deletion drivers/pci/hotplug/rpadlpar_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ struct kobj_type ktype_dlpar_io = {
struct kset dlpar_io_kset = {
.kobj = {.ktype = &ktype_dlpar_io,
.parent = &pci_hotplug_slots_subsys.kobj},
.ktype = &ktype_dlpar_io,
};

int dlpar_sysfs_init(void)
Expand Down
2 changes: 1 addition & 1 deletion drivers/uio/uio.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
if (!map_found) {
map_found = 1;
kobject_set_name(&idev->map_attr_kset.kobj,"maps");
idev->map_attr_kset.ktype = &map_attr_type;
idev->map_attr_kset.kobj.ktype = &map_attr_type;
idev->map_attr_kset.kobj.parent = &idev->dev->kobj;
ret = kset_register(&idev->map_attr_kset);
if (ret)
Expand Down
4 changes: 2 additions & 2 deletions fs/configfs/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void configfs_release_fs(void)
}


static decl_subsys(config, NULL, NULL);
static decl_subsys(config, NULL);

static int __init configfs_init(void)
{
Expand All @@ -140,7 +140,7 @@ static int __init configfs_init(void)
if (!configfs_dir_cachep)
goto out;

kobj_set_kset_s(&config_subsys, kernel_subsys);
config_subsys.kobj.kset = &kernel_subsys;
err = subsystem_register(&config_subsys);
if (err) {
kmem_cache_destroy(configfs_dir_cachep);
Expand Down
4 changes: 2 additions & 2 deletions fs/debugfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,13 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
}
EXPORT_SYMBOL_GPL(debugfs_rename);

static decl_subsys(debug, NULL, NULL);
static decl_subsys(debug, NULL);

static int __init debugfs_init(void)
{
int retval;

kobj_set_kset_s(&debug_subsys, kernel_subsys);
debug_subsys.kobj.kset = &kernel_subsys;
retval = subsystem_register(&debug_subsys);
if (retval)
return retval;
Expand Down
Loading

0 comments on commit 3514fac

Please sign in to comment.