From patchwork Mon Jun 9 02:04:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 895131 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CDC382866 for ; Mon, 9 Jun 2025 02:04:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749434686; cv=none; b=mVq7j7lwd8EyafgCA7q1wnxk+H63p6eG4KHHbuXU23Xy2PSoNQE0lPsGjv1w/SB6iwozHzwrwPy0ttXeOsfZk5yjhPPV/sooPtbIUGd63w0SoHSMrB0HClsmONA7V+7H775wm6ZaZphZO5I972SJknhvPAZvNY8YmMdICsvvpeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749434686; c=relaxed/simple; bh=sODM0sgcTmf0q3pCfBBBQ3Z4sJiyGddOs7xRMPvE1xM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MQK6pvqt4mU/VyBeUxkMnUxGX4hPtYYbCgSDpVmMHeNJmYFUpVNRIUmFOgI4SyKYaGy9qrov7otrBzePdc9es681vX3kBLQTcFAm5XXArlNGDOfUgrlvnc+3mNjqHug3h8dRCR1qllfl6TInVf9+8LiyMRtkIrPoxN+ggrqW8O4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q1T6H3BW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q1T6H3BW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95D72C4CEF2; Mon, 9 Jun 2025 02:04:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749434686; bh=sODM0sgcTmf0q3pCfBBBQ3Z4sJiyGddOs7xRMPvE1xM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q1T6H3BWha5rXhmt42yovv2VHEqjMem8YyfBz6LJX6EeI++TM7I554gw2QW1q563i tFsNT28RuKuDRTXxQZ8kUZ+CsOmVApc6LIkD4tdbIb18CwQsbn0QRDGszr6XkNvtY6 Lf6/5dtgw/lOF9IV8pxE6GF5CqWE3chKM9CFFf5Hvbby3TdYIC0bri/lF1QpTH96ks mELkh1sRaScbo3puDbYTTZs5jmq6EZ0q5izXEodFMsE2lUgp5osQZbmiUICoH0YGK5 bljg3doqLrDVOn8wzd8XjEioZjPsDXHRK75+g15EU1SNbORC17V8lcOlYrc48qDPk9 FcxXcQvMpqKtw== From: Mario Limonciello To: mario.limonciello@amd.com Cc: linux-usb@vger.kernel.org, mathias.nyman@intel.com, gregkh@linuxfoundation.org Subject: [PATCH 2/4] PCI: Fix runtime PM usage count underflow Date: Sun, 8 Jun 2025 21:04:34 -0500 Message-ID: <20250609020434.287559-2-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250609020434.287559-1-superm1@kernel.org> References: <20250609020434.287559-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello 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. This involves setting the device error state to `pci_channel_io_perm_failure`. 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 is in the error state and skip the call for this cleanup path. Signed-off-by: Mario Limonciello --- 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 9f6e145d93d62..ab4cfdfc8fbc0 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->error_state != pci_channel_io_perm_failure) + pm_runtime_put_sync(dev); /* * If the device is still on, set the power state as "unknown",