static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
 {
        struct pci_dev *dev;
+       struct pci_slot *slot;
        u32 l;
        u8 hdr_type;
        int delay = 1;
        dev->error_state = pci_channel_io_normal;
        set_pcie_port_type(dev);
 
+       list_for_each_entry(slot, &bus->slots, list)
+               if (PCI_SLOT(devfn) == slot->number)
+                       dev->slot = slot;
+
        /* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
           set this higher, assuming the system even supports it.  */
        dev->dma_mask = 0xffffffff;
 
 
 static void pci_slot_release(struct kobject *kobj)
 {
+       struct pci_dev *dev;
        struct pci_slot *slot = to_pci_slot(kobj);
 
        pr_debug("%s: releasing pci_slot on %x:%d\n", __func__,
                 slot->bus->number, slot->number);
 
+       list_for_each_entry(dev, &slot->bus->devices, bus_list)
+               if (PCI_SLOT(dev->devfn) == slot->number)
+                       dev->slot = NULL;
+
        list_del(&slot->list);
 
        kfree(slot);
 struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
                                 const char *name)
 {
+       struct pci_dev *dev;
        struct pci_slot *slot;
        int err;
 
        INIT_LIST_HEAD(&slot->list);
        list_add(&slot->list, &parent->slots);
 
+       list_for_each_entry(dev, &parent->devices, bus_list)
+               if (PCI_SLOT(dev->devfn) == slot_nr)
+                       dev->slot = slot;
+
        /* Don't care if debug printk has a -1 for slot_nr */
        pr_debug("%s: created pci_slot on %04x:%02x:%02x\n",
                 __func__, pci_domain_nr(parent), parent->number, slot_nr);