diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2021-10-12 15:42:59 -0500 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2021-10-12 17:37:15 -0500 |
commit | 8e9028b3790ddb02c407e1a4da0ab7cf82790e7e (patch) | |
tree | 4d47d8f4146693c6a91f18b236d446a98da93ea2 /include/linux/pci.h | |
parent | e4e737bb5c170df6135a127739a9e6148ee3da82 (diff) | |
download | lwn-8e9028b3790ddb02c407e1a4da0ab7cf82790e7e.tar.gz lwn-8e9028b3790ddb02c407e1a4da0ab7cf82790e7e.zip |
PCI: Return NULL for to_pci_driver(NULL)
to_pci_driver() takes a pointer to a struct device_driver and uses
container_of() to find the struct pci_driver that contains it.
If given a NULL pointer to a struct device_driver, return a NULL pci_driver
pointer instead of applying container_of() to NULL.
This simplifies callers that would otherwise have to check for a NULL
pointer first.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'include/linux/pci.h')
-rw-r--r-- | include/linux/pci.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/include/linux/pci.h b/include/linux/pci.h index cd8aa6fce204..a2d62165a7f7 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -900,7 +900,10 @@ struct pci_driver { struct pci_dynids dynids; }; -#define to_pci_driver(drv) container_of(drv, struct pci_driver, driver) +static inline struct pci_driver *to_pci_driver(struct device_driver *drv) +{ + return drv ? container_of(drv, struct pci_driver, driver) : NULL; +} /** * PCI_DEVICE - macro used to describe a specific PCI device |