All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mario Limonciello <superm1@kernel.org>
To: mario.limonciello@amd.com, bhelgaas@google.com
Cc: linux-pci@vger.kernel.org
Subject: [PATCH v2 2/2] PCI: Fix runtime PM usage count underflow
Date: Mon, 16 Jun 2025 14:26:57 -0500	[thread overview]
Message-ID: <20250616192813.3829124-3-superm1@kernel.org> (raw)
In-Reply-To: <20250616192813.3829124-1-superm1@kernel.org>

From: Mario Limonciello <mario.limonciello@amd.com>

When a USB4 dock is unplugged the PCIe bridge it's connected to will
remove issue a "Link Down" and "Card not detected event". The PCI core
will treat this as a surprise hotplug event and unconfigure all downstream
devices.

When PCI core gets to the point that the device is removed using
pci_device_remove() the runtime count has already been decremented and
so calling pm_runtime_put_sync() will cause an underflow.

Detect the device ishas been disconnected and skip the call for this
cleanup path.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v2:
 * Use pci_dev_is_disconnected()
v1: https://lore.kernel.org/linux-usb/20250609020223.269407-1-superm1@kernel.org/T/#mf95c947990d016fbfccfd11afe60b8ae08aafa0b
---
 drivers/pci/pci-driver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 67db34fd10ee7..0d4c67829958b 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -479,7 +479,8 @@ static void pci_device_remove(struct device *dev)
 	pci_iov_remove(pci_dev);
 
 	/* Undo the runtime PM settings in local_pci_probe() */
-	pm_runtime_put_sync(dev);
+	if (!pci_dev_is_disconnected(pci_dev))
+		pm_runtime_put_sync(dev);
 
 	/*
 	 * If the device is still on, set the power state as "unknown",
-- 
2.43.0


  parent reply	other threads:[~2025-06-16 19:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16 19:26 [PATCH v2 0/2] Don't make noise about disconnected USB4 devices Mario Limonciello
2025-06-16 19:26 ` [PATCH v2 1/2] PCI: Don't show errors on inaccessible PCI devices Mario Limonciello
2025-06-19  6:14   ` Lukas Wunner
2025-06-19 13:36     ` Mario Limonciello
2025-06-16 19:26 ` Mario Limonciello [this message]
2025-06-19  6:09   ` [PATCH v2 2/2] PCI: Fix runtime PM usage count underflow Lukas Wunner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250616192813.3829124-3-superm1@kernel.org \
    --to=superm1@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.