fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / pci / hotplug / fakephp.c
index 060d747..e27907c 100644 (file)
  * Enabling PCI devices is left as an exercise for the reader...
  *
  */
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/pci.h>
+#include <linux/pci_hotplug.h>
 #include <linux/init.h>
 #include <linux/string.h>
 #include <linux/slab.h>
-#include "pci_hotplug.h"
 #include "../pci.h"
 
 #if !defined(MODULE)
@@ -95,15 +94,13 @@ static int add_slot(struct pci_dev *dev)
        struct hotplug_slot *slot;
        int retval = -ENOMEM;
 
-       slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
+       slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
        if (!slot)
                goto error;
-       memset(slot, 0, sizeof(*slot));
 
-       slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
+       slot->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
        if (!slot->info)
                goto error_slot;
-       memset(slot->info, 0, sizeof(struct hotplug_slot_info));
 
        slot->info->power_status = 1;
        slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
@@ -179,17 +176,25 @@ static void pci_rescan_slot(struct pci_dev *temp)
        struct pci_bus *bus = temp->bus;
        struct pci_dev *dev;
        int func;
+       int retval;
        u8 hdr_type;
+
        if (!pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type)) {
                temp->hdr_type = hdr_type & 0x7f;
-               if (!pci_find_slot(bus->number, temp->devfn)) {
+               if ((dev = pci_get_slot(bus, temp->devfn)) != NULL)
+                       pci_dev_put(dev);
+               else {
                        dev = pci_scan_single_device(bus, temp->devfn);
                        if (dev) {
                                dbg("New device on %s function %x:%x\n",
                                        bus->name, temp->devfn >> 3,
                                        temp->devfn & 7);
-                               pci_bus_add_device(dev);
-                               add_slot(dev);
+                               retval = pci_bus_add_device(dev);
+                               if (retval)
+                                       dev_err(&dev->dev, "error adding "
+                                               "device, continuing.\n");
+                               else
+                                       add_slot(dev);
                        }
                }
                /* multifunction device? */
@@ -202,14 +207,20 @@ static void pci_rescan_slot(struct pci_dev *temp)
                                continue;
                        temp->hdr_type = hdr_type & 0x7f;
 
-                       if (!pci_find_slot(bus->number, temp->devfn)) {
+                       if ((dev = pci_get_slot(bus, temp->devfn)) != NULL)
+                               pci_dev_put(dev);
+                       else {
                                dev = pci_scan_single_device(bus, temp->devfn);
                                if (dev) {
                                        dbg("New device on %s function %x:%x\n",
                                                bus->name, temp->devfn >> 3,
                                                temp->devfn & 7);
-                                       pci_bus_add_device(dev);
-                                       add_slot(dev);
+                                       retval = pci_bus_add_device(dev);
+                                       if (retval)
+                                               dev_err(&dev->dev, "error adding "
+                                                       "device, continuing.\n");
+                                       else
+                                               add_slot(dev);
                                }
                        }
                }
@@ -227,11 +238,10 @@ static void pci_rescan_bus(const struct pci_bus *bus)
 {
        unsigned int devfn;
        struct pci_dev *dev;
-       dev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
+       dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
        if (!dev)
                return;
 
-       memset(dev, 0, sizeof(dev));
        dev->bus = (struct pci_bus*)bus;
        dev->sysdata = bus->sysdata;
        for (devfn = 0; devfn < 0x100; devfn += 8) {
@@ -299,7 +309,7 @@ static int disable_slot(struct hotplug_slot *slot)
        /* search for subfunctions and disable them first */
        if (!(dslot->dev->devfn & 7)) {
                for (func = 1; func < 8; func++) {
-                       dev = pci_find_slot(dslot->dev->bus->number,
+                       dev = pci_get_slot(dslot->dev->bus,
                                        dslot->dev->devfn + func);
                        if (dev) {
                                hslot = get_slot_from_dev(dev);
@@ -309,6 +319,7 @@ static int disable_slot(struct hotplug_slot *slot)
                                        err("Hotplug slot not found for subfunction of PCI device\n");
                                        return -ENODEV;
                                }
+                               pci_dev_put(dev);
                        } else
                                dbg("No device in slot found\n");
                }