]> git.neil.brown.name Git - history.git/commitdiff
Small driver model/driverfs update.
authorPatrick Mochel <mochel@segfault.osdlab.org>
Fri, 8 Feb 2002 08:19:17 +0000 (00:19 -0800)
committerPatrick Mochel <mochel@segfault.osdlab.org>
Fri, 8 Feb 2002 08:19:17 +0000 (00:19 -0800)
drivers/base/core.c
drivers/pcmcia/cardbus.c
fs/driverfs/inode.c

index 0cc155572054a3064c810347160f64cbe63289b1..4a8b527c6792763158316d2b1a8d89effe9568fb 100644 (file)
 # define DBG(x...)
 #endif
 
-static struct device * device_root;
+static struct device device_root = {
+       bus_id:         "root",
+       name:           "System Root",
+};
 
 int (*platform_notify)(struct device * dev) = NULL;
 int (*platform_notify_remove)(struct device * dev) = NULL;
@@ -49,9 +52,9 @@ int device_register(struct device *dev)
        spin_lock_init(&dev->lock);
        atomic_set(&dev->refcount,2);
 
-       if (dev != device_root) {
+       if (dev != &device_root) {
                if (!dev->parent)
-                       dev->parent = device_root;
+                       dev->parent = &device_root;
                get_device(dev->parent);
                list_add_tail(&dev->node,&dev->parent->children);
        }
@@ -117,16 +120,10 @@ void put_device(struct device * dev)
 
 static int __init device_init_root(void)
 {
-       device_root = kmalloc(sizeof(*device_root),GFP_KERNEL);
-       if (!device_root)
-               return -ENOMEM;
-       memset(device_root,0,sizeof(*device_root));
-       strcpy(device_root->bus_id,"root");
-       strcpy(device_root->name,"System Root");
-       return device_register(device_root);
+       return device_register(&device_root);
 }
 
-static int __init device_driver_init(void)
+static int __init device_init(void)
 {
        int error = 0;
 
@@ -141,17 +138,12 @@ static int __init device_driver_init(void)
                return error;
        }
 
-       error = device_init_root();
-       if (error) {
+       if ((error = device_init_root()))
                printk(KERN_ERR "%s: device root init failed!\n", __FUNCTION__);
-               return error;
-       }
-
-       DBG("DEV: Done Initialising\n");
        return error;
 }
 
-subsys_initcall(device_driver_init);
+subsys_initcall(device_init);
 
 EXPORT_SYMBOL(device_register);
 EXPORT_SYMBOL(put_device);
index 875160beb31c1efd5d6f14491f0420f6c8f24551..84df2ce5bf5e1e8d9b11d081ec43acccb0c24993 100644 (file)
@@ -279,6 +279,12 @@ int cb_alloc(socket_info_t * s)
                pci_readw(dev, PCI_DEVICE_ID, &dev->device);
                dev->hdr_type = hdr & 0x7f;
 
+               dev->dev.parent = bus->device;
+               dev->dev.sysdata = bus->sysdata;
+               strcpy(dev->dev.name, dev->name);
+               strcpy(dev->dev.bus_id, dev->slot_name);
+               device_register(&dev->dev);
+
                pci_setup_device(dev);
 
                /* FIXME: Do we need to enable the expansion ROM? */
index 54e35bce866d83f6427cc5ea52da3693447b9804..9502dc7cd85d1e662edbd3a5d3281d9338a5c99e 100644 (file)
@@ -245,6 +245,9 @@ driverfs_read_file(struct file *file, char *buf, size_t count, loff_t *ppos)
        if (!entry->show)
                return 0;
 
+       if (count > PAGE_SIZE)
+               count = PAGE_SIZE;
+
        dev = list_entry(entry->parent,struct device, dir);
 
        page = (unsigned char*)__get_free_page(GFP_KERNEL);
@@ -260,7 +263,8 @@ driverfs_read_file(struct file *file, char *buf, size_t count, loff_t *ppos)
                        if (len < 0)
                                retval = len;
                        break;
-               }
+               } else if (len > count)
+                       len = count;
 
                if (copy_to_user(buf,page,len)) {
                        retval = -EFAULT;