Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: Create alloc_pci_dev(), the one true way to create a struct pci_dev

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>

authored by

Michael Ellerman and committed by
Greg Kroah-Hartman
65891215 c9953a73

+17
+15
drivers/pci/probe.c
··· 846 846 kfree(dev); 847 847 } 848 848 849 + struct pci_dev *alloc_pci_dev(void) 850 + { 851 + struct pci_dev *dev; 852 + 853 + dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL); 854 + if (!dev) 855 + return NULL; 856 + 857 + INIT_LIST_HEAD(&dev->global_list); 858 + INIT_LIST_HEAD(&dev->bus_list); 859 + 860 + return dev; 861 + } 862 + EXPORT_SYMBOL(alloc_pci_dev); 863 + 849 864 /* 850 865 * Read the config data for a PCI device, sanity-check it 851 866 * and fill in the dev structure...
+2
include/linux/pci.h
··· 193 193 #endif 194 194 }; 195 195 196 + extern struct pci_dev *alloc_pci_dev(void); 197 + 196 198 #define pci_dev_g(n) list_entry(n, struct pci_dev, global_list) 197 199 #define pci_dev_b(n) list_entry(n, struct pci_dev, bus_list) 198 200 #define to_pci_dev(n) container_of(n, struct pci_dev, dev)