]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/base/bus.c
Driver core: make sysfs uevent-attributes static
[linux-2.6-omap-h63xx.git] / drivers / base / bus.c
index 20b6dc8706fa6764197bd07930ea624e90dbbba1..ff850d1b0d92020648021f4aa77371225de98239 100644 (file)
@@ -17,7 +17,7 @@
 #include "power/power.h"
 
 #define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr)
-#define to_bus(obj) container_of(obj, struct bus_type, subsys.kset.kobj)
+#define to_bus(obj) container_of(obj, struct bus_type, subsys.kobj)
 
 /*
  * sysfs bindings for drivers
@@ -63,8 +63,19 @@ static struct sysfs_ops driver_sysfs_ops = {
 
 static void driver_release(struct kobject * kobj)
 {
-       struct device_driver * drv = to_driver(kobj);
-       complete(&drv->unloaded);
+       /*
+        * Yes this is an empty release function, it is this way because struct
+        * device is always a static object, not a dynamic one.  Yes, this is
+        * not nice and bad, but remember, drivers are code, reference counted
+        * by the module count, not a device, which is really data.  And yes,
+        * in the future I do want to have all drivers be created dynamically,
+        * and am working toward that goal, but it will take a bit longer...
+        *
+        * But do not let this example give _anyone_ the idea that they can
+        * create a release function without any code in it at all, to do that
+        * is almost always wrong.  If you have any questions about this,
+        * please send an email to <greg@kroah.com>
+        */
 }
 
 static struct kobj_type ktype_driver = {
@@ -112,7 +123,7 @@ int bus_create_file(struct bus_type * bus, struct bus_attribute * attr)
 {
        int error;
        if (get_bus(bus)) {
-               error = sysfs_create_file(&bus->subsys.kset.kobj, &attr->attr);
+               error = sysfs_create_file(&bus->subsys.kobj, &attr->attr);
                put_bus(bus);
        } else
                error = -EINVAL;
@@ -122,17 +133,29 @@ int bus_create_file(struct bus_type * bus, struct bus_attribute * attr)
 void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr)
 {
        if (get_bus(bus)) {
-               sysfs_remove_file(&bus->subsys.kset.kobj, &attr->attr);
+               sysfs_remove_file(&bus->subsys.kobj, &attr->attr);
                put_bus(bus);
        }
 }
 
-static struct kobj_type ktype_bus = {
+static struct kobj_type bus_ktype = {
        .sysfs_ops      = &bus_sysfs_ops,
+};
+
+static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
+{
+       struct kobj_type *ktype = get_ktype(kobj);
 
+       if (ktype == &bus_ktype)
+               return 1;
+       return 0;
+}
+
+static struct kset_uevent_ops bus_uevent_ops = {
+       .filter = bus_uevent_filter,
 };
 
-static decl_subsys(bus, &ktype_bus, NULL);
+static decl_subsys(bus, &bus_ktype, &bus_uevent_ops);
 
 
 #ifdef CONFIG_HOTPLUG
@@ -386,7 +409,7 @@ static void device_remove_attrs(struct bus_type * bus, struct device * dev)
 static int make_deprecated_bus_links(struct device *dev)
 {
        return sysfs_create_link(&dev->kobj,
-                                &dev->bus->subsys.kset.kobj, "bus");
+                                &dev->bus->subsys.kobj, "bus");
 }
 
 static void remove_deprecated_bus_links(struct device *dev)
@@ -420,7 +443,7 @@ int bus_add_device(struct device * dev)
                if (error)
                        goto out_id;
                error = sysfs_create_link(&dev->kobj,
-                               &dev->bus->subsys.kset.kobj, "subsystem");
+                               &dev->bus->subsys.kobj, "subsystem");
                if (error)
                        goto out_subsys;
                error = make_deprecated_bus_links(dev);
@@ -545,34 +568,29 @@ static void remove_bind_files(struct device_driver *drv)
        driver_remove_file(drv, &driver_attr_unbind);
 }
 
+static BUS_ATTR(drivers_probe, S_IWUSR, NULL, store_drivers_probe);
+static BUS_ATTR(drivers_autoprobe, S_IWUSR | S_IRUGO,
+               show_drivers_autoprobe, store_drivers_autoprobe);
+
 static int add_probe_files(struct bus_type *bus)
 {
        int retval;
 
-       bus->drivers_probe_attr.attr.name = "drivers_probe";
-       bus->drivers_probe_attr.attr.mode = S_IWUSR;
-       bus->drivers_probe_attr.attr.owner = bus->owner;
-       bus->drivers_probe_attr.store = store_drivers_probe;
-       retval = bus_create_file(bus, &bus->drivers_probe_attr);
+       retval = bus_create_file(bus, &bus_attr_drivers_probe);
        if (retval)
                goto out;
 
-       bus->drivers_autoprobe_attr.attr.name = "drivers_autoprobe";
-       bus->drivers_autoprobe_attr.attr.mode = S_IWUSR | S_IRUGO;
-       bus->drivers_autoprobe_attr.attr.owner = bus->owner;
-       bus->drivers_autoprobe_attr.show = show_drivers_autoprobe;
-       bus->drivers_autoprobe_attr.store = store_drivers_autoprobe;
-       retval = bus_create_file(bus, &bus->drivers_autoprobe_attr);
+       retval = bus_create_file(bus, &bus_attr_drivers_autoprobe);
        if (retval)
-               bus_remove_file(bus, &bus->drivers_probe_attr);
+               bus_remove_file(bus, &bus_attr_drivers_probe);
 out:
        return retval;
 }
 
 static void remove_probe_files(struct bus_type *bus)
 {
-       bus_remove_file(bus, &bus->drivers_autoprobe_attr);
-       bus_remove_file(bus, &bus->drivers_probe_attr);
+       bus_remove_file(bus, &bus_attr_drivers_autoprobe);
+       bus_remove_file(bus, &bus_attr_drivers_probe);
 }
 #else
 static inline int add_bind_files(struct device_driver *drv) { return 0; }
@@ -592,14 +610,15 @@ int bus_add_driver(struct device_driver *drv)
        int error = 0;
 
        if (!bus)
-               return 0;
+               return -EINVAL;
 
        pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
        error = kobject_set_name(&drv->kobj, "%s", drv->name);
        if (error)
                goto out_put_bus;
        drv->kobj.kset = &bus->drivers;
-       if ((error = kobject_register(&drv->kobj)))
+       error = kobject_register(&drv->kobj);
+       if (error)
                goto out_put_bus;
 
        if (drv->bus->drivers_autoprobe) {
@@ -749,7 +768,8 @@ static int bus_add_attrs(struct bus_type * bus)
 
        if (bus->bus_attrs) {
                for (i = 0; attr_name(bus->bus_attrs[i]); i++) {
-                       if ((error = bus_create_file(bus,&bus->bus_attrs[i])))
+                       error = bus_create_file(bus,&bus->bus_attrs[i]);
+                       if (error)
                                goto Err;
                }
        }
@@ -799,7 +819,7 @@ int bus_register(struct bus_type * bus)
 
        BLOCKING_INIT_NOTIFIER_HEAD(&bus->bus_notifier);
 
-       retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name);
+       retval = kobject_set_name(&bus->subsys.kobj, "%s", bus->name);
        if (retval)
                goto out;
 
@@ -809,13 +829,13 @@ int bus_register(struct bus_type * bus)
                goto out;
 
        kobject_set_name(&bus->devices.kobj, "devices");
-       bus->devices.subsys = &bus->subsys;
+       bus->devices.kobj.parent = &bus->subsys.kobj;
        retval = kset_register(&bus->devices);
        if (retval)
                goto bus_devices_fail;
 
        kobject_set_name(&bus->drivers.kobj, "drivers");
-       bus->drivers.subsys = &bus->subsys;
+       bus->drivers.kobj.parent = &bus->subsys.kobj;
        bus->drivers.ktype = &ktype_driver;
        retval = kset_register(&bus->drivers);
        if (retval)