PCI: Return NULL for to_pci_driver(NULL)
authorBjorn Helgaas <bhelgaas@google.com>
Tue, 12 Oct 2021 20:42:59 +0000 (15:42 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 12 Oct 2021 22:37:15 +0000 (17:37 -0500)
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>
include/linux/pci.h

index cd8aa6fce2041c47725b2009f34669ac274f2290..a2d62165a7f72b19f2e66aec58a49a5420552e7d 100644 (file)
@@ -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