mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: linux-pci@vger.kernel.org, Bjorn Helgaas <bhelgaas@google.com>,
	"Maciej W. Rozycki" <macro@orcam.me.uk>,
	Kay Sievers <kay.sievers@vrfy.org>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	linux-kernel@vger.kernel.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>, stable@vger.kernel.org
Subject: [PATCH 01/11] PCI: Free device name when pci_setup_device() fails
Date: Mon,  9 Nov 2026 23:07:01 +0200	[thread overview]
Message-ID: <20261109210714.3862-2-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20261109210714.3862-1-ilpo.jarvinen@linux.intel.com>

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@linux.intel.com>
Cc: stable@vger.kernel.org
---

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


  reply	other threads:[~2026-11-09 21:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 21:07 [PATCH 00/11] PCI/CardBus: Disable properly when CARDBUS=n & fix some issues along the way Ilpo Järvinen
2026-11-09 21:07 ` Ilpo Järvinen [this message]
2026-11-09 21:07 ` [PATCH 02/11] PCI: Use Header Type in __pci_bridge_assign_resources() Ilpo Järvinen
2026-11-09 21:07 ` [PATCH 03/11] PCI: Use Header Type to detect CardBus bridges in pci_resource_alignment() Ilpo Järvinen
2026-11-09 21:07 ` [PATCH 04/11] PCI: Fix off-by-one in CardBus resource names Ilpo Järvinen
2026-11-09 21:07 ` [PATCH 05/11] PCI: Move pci_read_bases() wrapper with BUILD_BUG_ON() to pci.h Ilpo Järvinen
2026-11-09 21:07 ` [PATCH 06/11] mmc: sdricoh_cs: Depend on CARDBUS Ilpo Järvinen
2026-11-09 21:07 ` [RFC PATCH 07/11] pcmcia: yenta_socket: Always select CARDBUS Ilpo Järvinen
2026-11-09 21:07 ` [RFC PATCH 08/11] PCI: Move CardBus device setup to setup-cardbus.c Ilpo Järvinen
2026-11-09 21:07 ` [PATCH 09/11] PCI: Move CardBus legacy mode quirk " Ilpo Järvinen
2026-11-09 21:07 ` [RFC PATCH 10/11] PCI: Move Ricoh RL5C476 MMC " Ilpo Järvinen
2026-11-09 21:07 ` [PATCH 11/11] PCI: Move CardBus resource names " Ilpo Järvinen

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=20261109210714.3862-2-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=gregkh@suse.de \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=macro@orcam.me.uk \
    --cc=stable@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®