From e46ce4e8ef2eaa8271fa79ce7de2633a65643dc7 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 25 Sep 2026 11:25:39 -0700 Subject: scsi: PCI: Convert to_pci_dev() into an inline function Clang's context analysis checker performs alias analysis on expressions passed to annotations like __acquires(). Clang's alias analysis does not support container_of(). Convert to_pci_dev() from a macro into an inline function such that Clang recognizes multiple to_pci_dev() expressions as identical if the 'dev' argument is the same. It is on purpose that to_pci_dev() accepts a const pointer and returns a pointer that is not const. Any other choice, e.g. accepting a non-const pointer or returning a const pointer, triggers compiler errors in code that uses the to_pci_dev() macro. While _Generic() could be used to support const and non-const struct device pointers in a more elegant way, Clang's alias analysis does not support _Generic(). Acked-by: Bjorn Helgaas Signed-off-by: Bart Van Assche Link: https://patch.msgid.link/f147ad227b85439d56183e60e0332547b84441bc.1790360262.git.bvanassche@acm.org Signed-off-by: Martin K. Petersen (Oracle) --- include/linux/pci.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/pci.h b/include/linux/pci.h index d31a8d107b1e..68166c9f8158 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -611,7 +611,10 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev) struct pci_dev *pci_alloc_dev(struct pci_bus *bus); -#define to_pci_dev(n) container_of(n, struct pci_dev, dev) +static inline struct pci_dev *to_pci_dev(const struct device *dev) +{ + return container_of(dev, struct pci_dev, dev); +} #define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) #define for_each_pci_dev_reverse(d) \ while ((d = pci_get_device_reverse(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) -- cgit v1.2.3