diff options
| author | Patrick Mochel <mochel@osdl.org> | 2002-08-13 20:18:17 -0700 |
|---|---|---|
| committer | Patrick Mochel <mochel@osdl.org> | 2002-08-13 20:18:17 -0700 |
| commit | 70f7d2ec278ed64fa0cfc03a5b96ed35e2a20289 (patch) | |
| tree | 090cc0e4a572aeea311521e27a1286e162eb9484 /drivers/base | |
| parent | dc4c65dae461f3347cdc70df0db833f4708e0a99 (diff) | |
Remove device_root device; replace with global_device_list.
The device_root device was only a placeholder device that provided a head
for the global device list, and a parent directory for root bridge devices.
This removes the device and replaces with an explicit global_device_list
and a separate root directory. We never used any of the other fields in
device_root, and we special cased it. So, it's better off dead.
Diffstat (limited to 'drivers/base')
| -rw-r--r-- | drivers/base/base.h | 2 | ||||
| -rw-r--r-- | drivers/base/core.c | 38 | ||||
| -rw-r--r-- | drivers/base/fs/device.c | 22 | ||||
| -rw-r--r-- | drivers/base/power.c | 6 |
4 files changed, 33 insertions, 35 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h index 2ba238eba033..f0d934868945 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -6,7 +6,7 @@ # define DBG(x...) #endif -extern struct device device_root; +extern struct list_head global_device_list; extern spinlock_t device_lock; extern struct device * get_device_locked(struct device *); diff --git a/drivers/base/core.c b/drivers/base/core.c index 681ca2d2eecc..891e977d1bee 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -15,10 +15,7 @@ #include <linux/err.h> #include "base.h" -struct device device_root = { - .bus_id = "root", - .name = "System root", -}; +LIST_HEAD(global_device_list); int (*platform_notify)(struct device * dev) = NULL; int (*platform_notify_remove)(struct device * dev) = NULL; @@ -178,17 +175,15 @@ int device_register(struct device *dev) INIT_LIST_HEAD(&dev->bus_list); spin_lock_init(&dev->lock); atomic_set(&dev->refcount,2); - - if (dev != &device_root) { - if (!dev->parent) - dev->parent = &device_root; - get_device(dev->parent); - - spin_lock(&device_lock); + + spin_lock(&device_lock); + if (dev->parent) { + get_device_locked(dev->parent); list_add_tail(&dev->g_list,&dev->parent->g_list); list_add_tail(&dev->node,&dev->parent->children); - spin_unlock(&device_lock); - } + } else + list_add_tail(&dev->g_list,&global_device_list); + spin_unlock(&device_lock); pr_debug("DEV: registering device: ID = '%s', name = %s\n", dev->bus_id, dev->name); @@ -269,12 +264,8 @@ void put_device(struct device * dev) if (dev->release) dev->release(dev); - put_device(dev->parent); -} - -static int __init device_init_root(void) -{ - return device_register(&device_root); + if (dev->parent) + put_device(dev->parent); } static int __init device_init(void) @@ -282,14 +273,9 @@ static int __init device_init(void) int error; error = init_driverfs_fs(); - if (error) { - panic("DEV: could not initialize driverfs"); - return error; - } - error = device_init_root(); if (error) - printk(KERN_ERR "%s: device root init failed!\n", __FUNCTION__); - return error; + panic("DEV: could not initialize driverfs"); + return 0; } core_initcall(device_init); diff --git a/drivers/base/fs/device.c b/drivers/base/fs/device.c index 9e9efcc2cf76..1a1c71571dbe 100644 --- a/drivers/base/fs/device.c +++ b/drivers/base/fs/device.c @@ -10,11 +10,17 @@ #include <linux/device.h> #include <linux/module.h> #include <linux/string.h> +#include <linux/init.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/stat.h> #include <linux/limits.h> +static struct driver_dir_entry device_root_dir = { + .name = "root", + .mode = (S_IRWXU | S_IRUGO | S_IXUGO), +}; + extern struct device_attribute * device_default_files[]; #define to_dev_attr(_attr) container_of(_attr,struct device_attribute,attr) @@ -164,7 +170,7 @@ int device_bus_link(struct device * dev) * one to get to the 'bus' directory, and one to get to the root * of the fs.) */ - length += strlen("../../.."); + length += strlen("../../../root"); if (length > PATH_MAX) return -ENAMETOOLONG; @@ -174,7 +180,7 @@ int device_bus_link(struct device * dev) memset(path,0,length); /* our relative position */ - strcpy(path,"../../.."); + strcpy(path,"../../../root"); fill_devpath(dev,path,length); error = driverfs_create_symlink(&dev->bus->device_dir,dev->bus_id,path); @@ -207,13 +213,12 @@ int device_create_dir(struct driver_dir_entry * dir, struct driver_dir_entry * p */ int device_make_dir(struct device * dev) { - struct driver_dir_entry * parent = NULL; + struct driver_dir_entry * parent; struct device_attribute * entry; int error; int i; - if (dev->parent) - parent = &dev->parent->dir; + parent = dev->parent ? &dev->parent->dir : &device_root_dir; dev->dir.name = dev->bus_id; dev->dir.ops = &dev_attr_ops; @@ -229,5 +234,12 @@ int device_make_dir(struct device * dev) return error; } +static int device_driverfs_init(void) +{ + return driverfs_create_dir(&device_root_dir,NULL); +} + +core_initcall(device_driverfs_init); + EXPORT_SYMBOL(device_create_file); EXPORT_SYMBOL(device_remove_file); diff --git a/drivers/base/power.c b/drivers/base/power.c index b9621821c8fc..8dcea4ff85a0 100644 --- a/drivers/base/power.c +++ b/drivers/base/power.c @@ -34,7 +34,7 @@ int device_suspend(u32 state, u32 level) printk(KERN_EMERG "Suspending Devices\n"); spin_lock(&device_lock); - list_for_each(node,&device_root.g_list) { + list_for_each(node,&global_device_list) { struct device * dev = get_device_locked(to_dev(node)); if (dev) { spin_unlock(&device_lock); @@ -65,7 +65,7 @@ void device_resume(u32 level) struct device * prev = NULL; spin_lock(&device_lock); - list_for_each_prev(node,&device_root.g_list) { + list_for_each_prev(node,&global_device_list) { struct device * dev = get_device_locked(to_dev(node)); if (dev) { spin_unlock(&device_lock); @@ -98,7 +98,7 @@ void device_shutdown(void) printk(KERN_EMERG "Shutting down devices\n"); spin_lock(&device_lock); - list_for_each(node,&device_root.g_list) { + list_for_each(node,&global_device_list) { struct device * dev = get_device_locked(to_dev(node)); if (dev) { spin_unlock(&device_lock); |
