]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/base/core.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/pci-2.6
[linux-2.6-omap-h63xx.git] / drivers / base / core.c
index c34a4d8842e12c1fb911c405b290637876a6ce92..0455aa78fa135cb04529efb281386d25423b2970 100644 (file)
@@ -180,10 +180,12 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
                        const char *path;
 
                        path = kobject_get_path(&parent->kobj, GFP_KERNEL);
-                       add_uevent_var(envp, num_envp, &i,
-                                      buffer, buffer_size, &length,
-                                      "PHYSDEVPATH=%s", path);
-                       kfree(path);
+                       if (path) {
+                               add_uevent_var(envp, num_envp, &i,
+                                              buffer, buffer_size, &length,
+                                              "PHYSDEVPATH=%s", path);
+                               kfree(path);
+                       }
 
                        add_uevent_var(envp, num_envp, &i,
                                       buffer, buffer_size, &length,
@@ -246,13 +248,71 @@ static struct kset_uevent_ops device_uevent_ops = {
        .uevent =       dev_uevent,
 };
 
+static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
+                          char *buf)
+{
+       struct kobject *top_kobj;
+       struct kset *kset;
+       char *envp[32];
+       char *data = NULL;
+       char *pos;
+       int i;
+       size_t count = 0;
+       int retval;
+
+       /* search the kset, the device belongs to */
+       top_kobj = &dev->kobj;
+       if (!top_kobj->kset && top_kobj->parent) {
+               do {
+                       top_kobj = top_kobj->parent;
+               } while (!top_kobj->kset && top_kobj->parent);
+       }
+       if (!top_kobj->kset)
+               goto out;
+       kset = top_kobj->kset;
+       if (!kset->uevent_ops || !kset->uevent_ops->uevent)
+               goto out;
+
+       /* respect filter */
+       if (kset->uevent_ops && kset->uevent_ops->filter)
+               if (!kset->uevent_ops->filter(kset, &dev->kobj))
+                       goto out;
+
+       data = (char *)get_zeroed_page(GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
+
+       /* let the kset specific function add its keys */
+       pos = data;
+       retval = kset->uevent_ops->uevent(kset, &dev->kobj,
+                                         envp, ARRAY_SIZE(envp),
+                                         pos, PAGE_SIZE);
+       if (retval)
+               goto out;
+
+       /* copy keys to file */
+       for (i = 0; envp[i]; i++) {
+               pos = &buf[count];
+               count += sprintf(pos, "%s\n", envp[i]);
+       }
+out:
+       free_page((unsigned long)data);
+       return count;
+}
+
 static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
                            const char *buf, size_t count)
 {
+       if (memcmp(buf, "add", 3) != 0)
+               dev_err(dev, "uevent: unsupported action-string; this will "
+                       "be ignored in a future kernel version");
        kobject_uevent(&dev->kobj, KOBJ_ADD);
        return count;
 }
 
+static struct device_attribute uevent_attr =
+       __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent);
+
 static int device_add_attributes(struct device *dev,
                                 struct device_attribute *attrs)
 {
@@ -366,6 +426,9 @@ static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
        return print_dev_t(buf, dev->devt);
 }
 
+static struct device_attribute devt_attr =
+       __ATTR(dev, S_IRUGO, show_dev, NULL);
+
 /*
  *     devices_subsys - structure to be registered with kobject core.
  */
@@ -430,9 +493,10 @@ void device_remove_bin_file(struct device *dev, struct bin_attribute *attr)
 EXPORT_SYMBOL_GPL(device_remove_bin_file);
 
 /**
- * device_schedule_callback - helper to schedule a callback for a device
+ * device_schedule_callback_owner - helper to schedule a callback for a device
  * @dev: device.
  * @func: callback function to invoke later.
+ * @owner: module owning the callback routine
  *
  * Attribute methods must not unregister themselves or their parent device
  * (which would amount to the same thing).  Attempts to do so will deadlock,
@@ -443,20 +507,23 @@ EXPORT_SYMBOL_GPL(device_remove_bin_file);
  * argument in the workqueue's process context.  @dev will be pinned until
  * @func returns.
  *
+ * This routine is usually called via the inline device_schedule_callback(),
+ * which automatically sets @owner to THIS_MODULE.
+ *
  * Returns 0 if the request was submitted, -ENOMEM if storage could not
- * be allocated.
+ * be allocated, -ENODEV if a reference to @owner isn't available.
  *
  * NOTE: This routine won't work if CONFIG_SYSFS isn't set!  It uses an
  * underlying sysfs routine (since it is intended for use by attribute
  * methods), and if sysfs isn't available you'll get nothing but -ENOSYS.
  */
-int device_schedule_callback(struct device *dev,
-               void (*func)(struct device *))
+int device_schedule_callback_owner(struct device *dev,
+               void (*func)(struct device *), struct module *owner)
 {
        return sysfs_schedule_callback(&dev->kobj,
-                       (void (*)(void *)) func, dev);
+                       (void (*)(void *)) func, dev, owner);
 }
-EXPORT_SYMBOL_GPL(device_schedule_callback);
+EXPORT_SYMBOL_GPL(device_schedule_callback_owner);
 
 static void klist_children_get(struct klist_node *n)
 {
@@ -506,7 +573,7 @@ static struct kobject * get_device_parent(struct device *dev,
        /* Set the parent to the class, not the parent device */
        /* this keeps sysfs from having a symlink to make old udevs happy */
        if (dev->class)
-               return &dev->class->subsys.kset.kobj;
+               return &dev->class->subsys.kobj;
        else if (parent)
                return &parent->kobj;
 
@@ -518,7 +585,7 @@ static struct kobject *virtual_device_parent(struct device *dev)
        static struct kobject *virtual_dir = NULL;
 
        if (!virtual_dir)
-               virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual");
+               virtual_dir = kobject_add_dir(&devices_subsys.kobj, "virtual");
 
        return virtual_dir;
 }
@@ -620,43 +687,23 @@ int device_add(struct device *dev)
                blocking_notifier_call_chain(&dev->bus->bus_notifier,
                                             BUS_NOTIFY_ADD_DEVICE, dev);
 
-       dev->uevent_attr.attr.name = "uevent";
-       dev->uevent_attr.attr.mode = S_IWUSR;
-       if (dev->driver)
-               dev->uevent_attr.attr.owner = dev->driver->owner;
-       dev->uevent_attr.store = store_uevent;
-       error = device_create_file(dev, &dev->uevent_attr);
+       error = device_create_file(dev, &uevent_attr);
        if (error)
                goto attrError;
 
        if (MAJOR(dev->devt)) {
-               struct device_attribute *attr;
-               attr = kzalloc(sizeof(*attr), GFP_KERNEL);
-               if (!attr) {
-                       error = -ENOMEM;
-                       goto ueventattrError;
-               }
-               attr->attr.name = "dev";
-               attr->attr.mode = S_IRUGO;
-               if (dev->driver)
-                       attr->attr.owner = dev->driver->owner;
-               attr->show = show_dev;
-               error = device_create_file(dev, attr);
-               if (error) {
-                       kfree(attr);
+               error = device_create_file(dev, &devt_attr);
+               if (error)
                        goto ueventattrError;
-               }
-
-               dev->devt_attr = attr;
        }
 
        if (dev->class) {
-               sysfs_create_link(&dev->kobj, &dev->class->subsys.kset.kobj,
+               sysfs_create_link(&dev->kobj, &dev->class->subsys.kobj,
                                  "subsystem");
                /* If this is not a "fake" compatible device, then create the
                 * symlink from the class to the device. */
-               if (dev->kobj.parent != &dev->class->subsys.kset.kobj)
-                       sysfs_create_link(&dev->class->subsys.kset.kobj,
+               if (dev->kobj.parent != &dev->class->subsys.kobj)
+                       sysfs_create_link(&dev->class->subsys.kobj,
                                          &dev->kobj, dev->bus_id);
                if (parent) {
                        sysfs_create_link(&dev->kobj, &dev->parent->kobj,
@@ -671,11 +718,14 @@ int device_add(struct device *dev)
                }
        }
 
-       if ((error = device_add_attrs(dev)))
+       error = device_add_attrs(dev);
+       if (error)
                goto AttrsError;
-       if ((error = device_pm_add(dev)))
+       error = device_pm_add(dev);
+       if (error)
                goto PMError;
-       if ((error = bus_add_device(dev)))
+       error = bus_add_device(dev);
+       if (error)
                goto BusError;
        kobject_uevent(&dev->kobj, KOBJ_ADD);
        bus_attach_device(dev);
@@ -705,17 +755,15 @@ int device_add(struct device *dev)
                                             BUS_NOTIFY_DEL_DEVICE, dev);
        device_remove_attrs(dev);
  AttrsError:
-       if (dev->devt_attr) {
-               device_remove_file(dev, dev->devt_attr);
-               kfree(dev->devt_attr);
-       }
+       if (MAJOR(dev->devt))
+               device_remove_file(dev, &devt_attr);
 
        if (dev->class) {
                sysfs_remove_link(&dev->kobj, "subsystem");
                /* If this is not a "fake" compatible device, remove the
                 * symlink from the class to the device. */
-               if (dev->kobj.parent != &dev->class->subsys.kset.kobj)
-                       sysfs_remove_link(&dev->class->subsys.kset.kobj,
+               if (dev->kobj.parent != &dev->class->subsys.kobj)
+                       sysfs_remove_link(&dev->class->subsys.kobj,
                                          dev->bus_id);
                if (parent) {
 #ifdef CONFIG_SYSFS_DEPRECATED
@@ -730,7 +778,7 @@ int device_add(struct device *dev)
                }
        }
  ueventattrError:
-       device_remove_file(dev, &dev->uevent_attr);
+       device_remove_file(dev, &uevent_attr);
  attrError:
        kobject_uevent(&dev->kobj, KOBJ_REMOVE);
        kobject_del(&dev->kobj);
@@ -807,16 +855,14 @@ void device_del(struct device * dev)
 
        if (parent)
                klist_del(&dev->knode_parent);
-       if (dev->devt_attr) {
-               device_remove_file(dev, dev->devt_attr);
-               kfree(dev->devt_attr);
-       }
+       if (MAJOR(dev->devt))
+               device_remove_file(dev, &devt_attr);
        if (dev->class) {
                sysfs_remove_link(&dev->kobj, "subsystem");
                /* If this is not a "fake" compatible device, remove the
                 * symlink from the class to the device. */
-               if (dev->kobj.parent != &dev->class->subsys.kset.kobj)
-                       sysfs_remove_link(&dev->class->subsys.kset.kobj,
+               if (dev->kobj.parent != &dev->class->subsys.kobj)
+                       sysfs_remove_link(&dev->class->subsys.kobj,
                                          dev->bus_id);
                if (parent) {
 #ifdef CONFIG_SYSFS_DEPRECATED
@@ -864,7 +910,7 @@ void device_del(struct device * dev)
                        up(&dev->class->sem);
                }
        }
-       device_remove_file(dev, &dev->uevent_attr);
+       device_remove_file(dev, &uevent_attr);
        device_remove_attrs(dev);
        bus_remove_device(dev);
 
@@ -1132,9 +1178,9 @@ int device_rename(struct device *dev, char *new_name)
 #endif
 
        if (dev->class) {
-               sysfs_remove_link(&dev->class->subsys.kset.kobj,
+               sysfs_remove_link(&dev->class->subsys.kobj,
                                  old_symlink_name);
-               sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
+               sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
                                  dev->bus_id);
        }
        put_device(dev);