diff mbox series

[v2,3/7] PCI/sysfs: Only allow IORESOURCE_IO in pci_resource_io()

Message ID 20210910202623.2293708-4-kw@linux.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show
Series PCI: Convert dynamic PCI resources sysfs objects into static | expand

Commit Message

Krzysztof Wilczyński Sept. 10, 2021, 8:26 p.m. UTC
Currently, when the sysfs attributes for PCI resources are added
dynamically, the read() and write() callbacks will only ever be set when
the underlying resource (a given BAR) has the IORESOURCE_IO flag set,
otherwise the callbacks will be NULL and any attempt to read from such
sysfs attribute will inherently fail.

After the conversion to the static sysfs objects, the read() and write()
callbacks will be always set for a given binary attribute (a particular
sysfs object). Thus, a check is added to the pci_resource_io() function
to ensure that a read against the underlying resource is supported and
that the IORESOURCE_IO flag is set.

Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
---
 drivers/pci/pci-sysfs.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index ccdd1e34aeee..e151d635fe04 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1084,6 +1084,9 @@  static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
 	int bar = (unsigned long)attr->private;
 	unsigned long port = off;
 
+	if (!(pci_resource_flags(pdev, bar) & IORESOURCE_IO))
+		return -EIO;
+
 	port += pci_resource_start(pdev, bar);
 
 	if (port > pci_resource_end(pdev, bar))