[PATCH 01/11] PCI: Free device name when pci_setup_device() fails

From: Ilpo Järvinen

Date: Mon Nov 09 2026 - 16:07:48 EST


pci_setup_device() calls dev_set_name(), which allocates the name, before
it can fail on an unknown Header Type. Its callers then free the device
with kfree() because device_initialize() has not yet been called, so the
name is never freed.

Free the name in the error path of pci_setup_device().

Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---

CardBus disabled case will reuse the same label after the move, thus
add the rollback path in this patch.

drivers/pci/probe.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 9a178e0e5f7f..1c2caf3ce664 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2194,8 +2194,8 @@ int pci_setup_device(struct pci_dev *dev)
default: /* unknown header */
pci_err(dev, "unknown header type %02x, ignoring device\n",
dev->hdr_type);
- pci_release_of_node(dev);
- return -EIO;
+ err = -EIO;
+ goto free_name;

bad:
pci_err(dev, "ignoring class %#08x (doesn't match header type %02x)\n",
@@ -2205,6 +2205,11 @@ int pci_setup_device(struct pci_dev *dev)

/* We found a fine healthy device, go go go... */
return 0;
+
+free_name:
+ kfree_const(dev->dev.kobj.name);
+ pci_release_of_node(dev);
+ return err;
}

static void pci_configure_mps(struct pci_dev *dev)
--
2.47.3