PCI/sysfs: Compile pci-sysfs.c only if CONFIG_SYSFS=y
authorLukas Wunner <lukas@wunner.de>
Mon, 30 Oct 2023 12:32:12 +0000 (13:32 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 5 Mar 2024 22:08:43 +0000 (16:08 -0600)
commitbe9c3a4c8be13326e434d8817d6dda6c5d2835f5
tree881a5fd354b77aa80d3f867b1019b407f985bb5a
parent6613476e225e090cc9aad49be7fa504e290dd33d
PCI/sysfs: Compile pci-sysfs.c only if CONFIG_SYSFS=y

It is possible to enable CONFIG_PCI but disable CONFIG_SYSFS and for
space-constrained devices such as routers, such a configuration may
actually make sense.

However pci-sysfs.c is compiled even if CONFIG_SYSFS is disabled,
unnecessarily increasing the kernel's size.

To rectify that:

* Move pci_mmap_fits() to mmap.c.  It is not only needed by
  pci-sysfs.c, but also proc.c.

* Move pci_dev_type to probe.c and make it private.  It references
  pci_dev_attr_groups in pci-sysfs.c.  Make that public instead for
  consistency with pci_dev_groups, pcibus_groups and pci_bus_groups,
  which are likewise public and referenced by struct definitions in
  pci-driver.c and probe.c.

* Define pci_dev_groups, pci_dev_attr_groups, pcibus_groups and
  pci_bus_groups to NULL if CONFIG_SYSFS is disabled.  Provide empty
  static inlines for pci_{create,remove}_legacy_files() and
  pci_{create,remove}_sysfs_dev_files().

Result:

vmlinux size is reduced by 122996 bytes in my arm 32-bit test build.

Link: https://lore.kernel.org/r/85ca95ae8e4d57ccf082c5c069b8b21eb141846e.1698668982.git.lukas@wunner.de
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
drivers/pci/Makefile
drivers/pci/mmap.c
drivers/pci/pci-sysfs.c
drivers/pci/pci.h
drivers/pci/probe.c