Skip to content

Commit

Permalink
PCI: Create alloc_pci_dev(), the one true way to create a struct pci_dev
Browse files Browse the repository at this point in the history
There are currently several places in the kernel where we kmalloc()
a struct pci_dev and start initialising it. It'd be preferable to
have an allocator so we can ensure the pci_dev is correctly initialised
in one place.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Michael Ellerman authored and Greg Kroah-Hartman committed May 3, 2007
1 parent c9953a7 commit 6589121
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions drivers/pci/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,21 @@ static void pci_release_bus_bridge_dev(struct device *dev)
kfree(dev);
}

struct pci_dev *alloc_pci_dev(void)
{
struct pci_dev *dev;

dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
if (!dev)
return NULL;

INIT_LIST_HEAD(&dev->global_list);
INIT_LIST_HEAD(&dev->bus_list);

return dev;
}
EXPORT_SYMBOL(alloc_pci_dev);

/*
* Read the config data for a PCI device, sanity-check it
* and fill in the dev structure...
Expand Down
2 changes: 2 additions & 0 deletions include/linux/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ struct pci_dev {
#endif
};

extern struct pci_dev *alloc_pci_dev(void);

#define pci_dev_g(n) list_entry(n, struct pci_dev, global_list)
#define pci_dev_b(n) list_entry(n, struct pci_dev, bus_list)
#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
Expand Down

0 comments on commit 6589121

Please sign in to comment.