Re: [PATCH v2 1/1] PCI: Introduce pci_bus_*() printing macros when device is not available

From: Joe Perches
Date: Thu Dec 09 2021 - 13:41:04 EST


On Thu, 2021-12-09 at 20:27 +0200, Andy Shevchenko wrote:
> In some cases PCI device structure is not available and we want to print
> information based on the bus and devfn parameters. For this cases introduce
> pci_bus_*() printing macros and replace in existing users.
[]
> diff --git a/include/linux/pci.h b/include/linux/pci.h
[]
> @@ -2482,4 +2482,12 @@ void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type);
> WARN_ONCE(condition, "%s %s: " fmt, \
> dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg)
>
> +#define pci_bus_printk(level, bus, devfn, fmt, arg...) \
> + printk(level "pci %04x:%02x:%02x.%d: " fmt, \
> + pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##arg)

I have a small preference for using ... and __VA_ARGS___

#define pci_bus_printk(level, bus, devfn, fmt, ...) \
printk(level "pci %04x:%02x:%02x.%d: " fmt, \
pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##__VA_ARGS__)

and likely this should have parentheses around bus

printk(level "pci %04x:%02x:%02x.%d: " fmt, \
pci_domain_nr(bus), (bus)->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##__VA_ARGS__)

> +#define pci_bus_err(bus, devfn, fmt, arg...) pci_bus_printk(KERN_ERR, bus, devfn, fmt, ##arg)
> +#define pci_bus_warn(bus, devfn, fmt, arg...) pci_bus_printk(KERN_WARNING, bus, devfn, fmt, ##arg)
> +#define pci_bus_info(bus, devfn, fmt, arg...) pci_bus_printk(KERN_INFO, bus, devfn, fmt, ##arg)

__VA_ARGS__ etc...