[PATCH] PCI: cpqhp: Release the device reference on config read failure

From: Zhu Jun

Date: Thu Nov 12 2026 - 02:27:58 EST


cpqhp_save_config() obtains a PCI device reference before saving its
configuration space. If a configuration read fails, the function
returns before reaching the matching pci_dev_put().

Drop the lookup reference on that error path as well as on success.

Fixes: 12a9da0fcb14 ("PCI Hotplug: cpqphp: don't use pci_find_slot()")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
drivers/pci/hotplug/cpqphp_pci.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/hotplug/cpqphp_pci.c b/drivers/pci/hotplug/cpqphp_pci.c
index 81c58b1ec200..c24d311c8e44 100644
--- a/drivers/pci/hotplug/cpqphp_pci.c
+++ b/drivers/pci/hotplug/cpqphp_pci.c
@@ -409,8 +409,10 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug)

for (cloop = 0; cloop < 0x20; cloop++) {
rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(device, function), cloop << 2, (u32 *) &(new_slot->config_space[cloop]));
- if (rc)
+ if (rc) {
+ pci_dev_put(new_slot->pci_dev);
return rc;
+ }
}

pci_dev_put(new_slot->pci_dev);
--
2.51.0