mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] PCI/PTM: fix refcount leak in pci_enable_ptm()
@ 2026-06-16 14:17 Wentao Liang
  2026-06-17  4:02 ` kernel test robot
  2026-06-17  7:38 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-06-16 14:17 UTC (permalink / raw)
  To: bhelgaas
  Cc: mika.westerberg, mani, andriy.shevchenko, kees, adiyenga, vulab,
	linux-pci, linux-kernel, stable

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@vger.kernel.org
Fixes: e8bdc5ea4816 ("PCI/PTM: Add pci_suspend_ptm() and pci_resume_ptm()")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-17  7:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-16 14:17 [PATCH] PCI/PTM: fix refcount leak in pci_enable_ptm() Wentao Liang
2026-06-17  4:02 ` kernel test robot
2026-06-17  7:38 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®