[PATCH] PCI/PTM: fix refcount leak in pci_enable_ptm()

From: Wentao Liang

Date: Tue Jun 16 2026 - 10:31:43 EST


When pci_enable_ptm() enables PTM for a device, it first
recursively calls itself on the parent. This increments the
parent's ptm_enable_cnt. If the subsequent __pci_enable_ptm()
call on the child fails, the error path only decrements the
child's ptm_enable_cnt but leaves the parent's counter
elevated. That refcount is never balanced, leading to a leak.

Fix this by calling pci_disable_ptm() for the parent on the
error path, reverting the parent's enable state. Add the call
right after the child's counter is decremented.

Cc: stable@xxxxxxxxxxxxxxx
Fixes: e8bdc5ea4816 ("PCI/PTM: Add pci_suspend_ptm() and pci_resume_ptm()")
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/pci/pcie/ptm.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/pci/pcie/ptm.c b/drivers/pci/pcie/ptm.c
index a41ffd1914de..01f6c7da7ca9 100644
--- a/drivers/pci/pcie/ptm.c
+++ b/drivers/pci/pcie/ptm.c
@@ -201,6 +201,8 @@ int pci_enable_ptm(struct pci_dev *dev)

rc = __pci_enable_ptm(dev);
if (rc) {
+ if (!dev->ptm_root)
+ pci_disable_ptm(parent);
atomic_dec(&dev->ptm_enable_cnt);
return rc;
}
--
2.34.1