[PATCH v2 4/6] PCI/sysfs: Avoid runtime PM at config-space EOF
From: Ziming Du
Date: Wed Jul 29 2026 - 23:06:33 EST
pci_read_config() and pci_write_config() only reject offsets beyond the
end of configuration space. An offset exactly at the end is reduced to a
zero-length transfer after the bounds adjustment, but still takes and
drops a runtime PM reference despite doing no work.
Return immediately for offsets at the end of configuration space.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Suggested-by: Krzysztof Wilczyński <kw@xxxxxxxxx>
Signed-off-by: Ziming Du <duziming2@xxxxxxxxxx>
---
drivers/pci/pci-sysfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 5ec0b245a69bd..a4f6559c619c7 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -718,7 +718,7 @@ static ssize_t pci_read_config(struct file *filp, struct kobject *kobj,
else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
size = 128;
- if (off > size)
+ if (off >= size)
return 0;
if (off + count > size) {
size -= off;
@@ -799,7 +799,7 @@ static ssize_t pci_write_config(struct file *filp, struct kobject *kobj,
add_taint(TAINT_USER, LOCKDEP_STILL_OK);
}
- if (off > dev->cfg_size)
+ if (off >= dev->cfg_size)
return 0;
if (off + count > dev->cfg_size) {
size = dev->cfg_size - off;
--
2.43.0