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@xxxxxxxxx> --- drivers/pci/pci-sysfs.c | 3 +++ 1 file changed, 3 insertions(+) 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)) -- 2.33.0