From: Mario Limonciello <mario.limonciello@xxxxxxx> 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 <mario.limonciello@xxxxxxx> --- 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", -- 2.43.0