]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
PCI/sysfs: Only allow supported resource types in I/O and MMIO helpers
authorKrzysztof Wilczyński <kwilczynski@kernel.org>
Fri, 8 May 2026 04:35:22 +0000 (04:35 +0000)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 8 May 2026 22:44:47 +0000 (17:44 -0500)
commit04fbecc947ec3a2149680d29b9cdc147fc012fba
treeb2eac0bea6bb33cf18e45d35f49b3c2b4d1c0939
parent77c5f3def45937f3f90ea4018cfdf9342b78b78a
PCI/sysfs: Only allow supported resource types in I/O and MMIO helpers

Currently, when the sysfs attributes for PCI resources are added
dynamically, the resource access callbacks are only set when the underlying
BAR type matches, using .read and .write for IORESOURCE_IO, and .mmap for
IORESOURCE_MEM or IORESOURCE_IO with arch_can_pci_mmap_io() support.  As
such, when the callback is not set, the operation inherently fails.

After the conversion to static attributes, visibility callbacks will
control which resource files appear for each BAR, but the callbacks
themselves will always be set.

Add a type check to pci_resource_io() and pci_mmap_resource() to return
-EIO for an unsupported resource type.

Use the new pci_resource_is_io() and pci_resource_is_mem() helpers for the
type checks, replacing the open-coded bitwise flag tests and also drop the
local struct resource pointer in pci_mmap_resource().

Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://patch.msgid.link/20260508043543.217179-4-kwilczynski@kernel.org
drivers/pci/pci-sysfs.c