Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 01/11] PCI: Free device name when pci_setup_device() fails
       [not found] <20261109210714.3862-1-ilpo.jarvinen@linux.intel.com>
@ 2026-11-09 21:07 ` Ilpo Järvinen
  2026-11-09 21:07 ` [PATCH 02/11] PCI: Use Header Type in __pci_bridge_assign_resources() Ilpo Järvinen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2026-11-09 21:07 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Maciej W. Rozycki, Kay Sievers,
	Greg Kroah-Hartman, linux-kernel
  Cc: Ilpo Järvinen, stable

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 02/11] PCI: Use Header Type in __pci_bridge_assign_resources()
       [not found] <20261109210714.3862-1-ilpo.jarvinen@linux.intel.com>
  2026-11-09 21:07 ` [PATCH 01/11] PCI: Free device name when pci_setup_device() fails Ilpo Järvinen
@ 2026-11-09 21:07 ` Ilpo Järvinen
  2026-12-01 17:18   ` 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
  3 siblings, 1 reply; 5+ messages in thread
From: Ilpo Järvinen @ 2026-11-09 21:07 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Maciej W. Rozycki, linux-kernel
  Cc: Ilpo Järvinen, stable

Commit b2fb5cc57469 ("PCI: Rely on config space header type, not class
code") converted bridge window sizing and assignment to use the Header
Type but __pci_bridge_assign_resources() still uses the Class Code to
decide how to program the bridge windows. A Type 1 bridge whose Class
Code is not PCI_CLASS_BRIDGE_PCI gets its windows sized and assigned but
they are never programmed into the bridge.

Use the Header Type also in __pci_bridge_assign_resources().

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---

I don't have known failure to point to with this, thus I've not added the
Fixes tag (the commit ref is available in the changelog if it's needed).

 drivers/pci/setup-bus.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index ed16ef7c26fa..6209773a35f1 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1636,12 +1636,12 @@ static void __pci_bridge_assign_resources(struct pci_dev *bridge,
 
 	__pci_bus_assign_resources(b, add_list, fail_head);
 
-	switch (bridge->class >> 8) {
-	case PCI_CLASS_BRIDGE_PCI:
+	switch (bridge->hdr_type) {
+	case PCI_HEADER_TYPE_BRIDGE:
 		pci_setup_bridge(b);
 		break;
 
-	case PCI_CLASS_BRIDGE_CARDBUS:
+	case PCI_HEADER_TYPE_CARDBUS:
 		pci_setup_cardbus_bridge(b);
 		break;
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 03/11] PCI: Use Header Type to detect CardBus bridges in pci_resource_alignment()
       [not found] <20261109210714.3862-1-ilpo.jarvinen@linux.intel.com>
  2026-11-09 21:07 ` [PATCH 01/11] PCI: Free device name when pci_setup_device() fails Ilpo Järvinen
  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 ` Ilpo Järvinen
  2026-11-09 21:07 ` [PATCH 04/11] PCI: Fix off-by-one in CardBus resource names Ilpo Järvinen
  3 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2026-11-09 21:07 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Maciej W. Rozycki, Ilpo Järvinen,
	linux-kernel
  Cc: stable

pci_resource_alignment() detects CardBus bridges by the Class Code while
the rest of the PCI core uses the Header Type.

When CONFIG_CARDBUS is not set, pci_cardbus_resource_alignment() returns
zero. A non-CardBus device that reports the CardBus Class Code then gets
zero alignment for all its resources, and pbus_size_mem() calls __ffs()
on it, which is undefined behavior. When CARDBUS is set, the device gets
CardBus window alignment instead of its own alignment.

Use pci_is_cardbus_bridge() in pci_resource_alignment() and make it take
a const pointer as pci_resource_alignment() has one.

Fixes: fd29d4ea09ba ("PCI: Separate CardBus setup & build it only with CONFIG_CARDBUS")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---
 drivers/pci/pci.h       | 2 +-
 drivers/pci/setup-res.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 77efa4c5c960..519918e24cc5 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -419,7 +419,7 @@ extern unsigned long pci_hotplug_mmio_size;
 extern unsigned long pci_hotplug_mmio_pref_size;
 extern unsigned long pci_hotplug_bus_size;
 
-static inline bool pci_is_cardbus_bridge(struct pci_dev *dev)
+static inline bool pci_is_cardbus_bridge(const struct pci_dev *dev)
 {
 	return dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
 }
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 376f09630a4a..d8d53861b4a6 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -255,7 +255,7 @@ resource_size_t pci_resource_alignment(const struct pci_dev *dev,
 
 	if (pci_resource_is_iov(resno))
 		return pci_sriov_resource_alignment(dev, resno);
-	if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
+	if (pci_is_cardbus_bridge(dev))
 		return pci_cardbus_resource_alignment(res);
 	return resource_alignment(res);
 }
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 04/11] PCI: Fix off-by-one in CardBus resource names
       [not found] <20261109210714.3862-1-ilpo.jarvinen@linux.intel.com>
                   ` (2 preceding siblings ...)
  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 ` Ilpo Järvinen
  3 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2026-11-09 21:07 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Maciej W. Rozycki, Puranjay Mohan,
	linux-kernel
  Cc: Ilpo Järvinen, stable

cardbus_name[] in pci_resource_name() has no entry for resource index 6
(PCI_ROM_RESOURCE). As a result, all names after it are off by one: the
last non-window resource is named "CardBus bridge window 0", each
CardBus bridge window is given the name of the preceding window, and
PCI_CB_BRIDGE_MEM_1_WINDOW falls outside the array.

Add the missing entry.

Fixes: 65f8e0beac5a ("PCI: Update BAR # and window messages")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---
 drivers/pci/pci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..46da873c9aac 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -839,6 +839,7 @@ const char *pci_resource_name(struct pci_dev *dev, unsigned int i)
 		"unknown",
 		"unknown",
 		"unknown",
+		"unknown",
 #ifdef CONFIG_PCI_IOV
 		"unknown",
 		"unknown",
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 02/11] PCI: Use Header Type in __pci_bridge_assign_resources()
  2026-11-09 21:07 ` [PATCH 02/11] PCI: Use Header Type in __pci_bridge_assign_resources() Ilpo Järvinen
@ 2026-12-01 17:18   ` Ilpo Järvinen
  0 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2026-12-01 17:18 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Maciej W. Rozycki, LKML, stable

[-- Attachment #1: Type: text/plain, Size: 764 bytes --]

On Mon, 9 Nov 2026, Ilpo Järvinen wrote:

> Commit b2fb5cc57469 ("PCI: Rely on config space header type, not class
> code") converted bridge window sizing and assignment to use the Header
> Type but __pci_bridge_assign_resources() still uses the Class Code to
> decide how to program the bridge windows. A Type 1 bridge whose Class
> Code is not PCI_CLASS_BRIDGE_PCI gets its windows sized and assigned but
> they are never programmed into the bridge.
> 
> Use the Header Type also in __pci_bridge_assign_resources().
> 
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Cc: stable@vger.kernel.org

This patch has been superceded by:

  https://lore.kernel.org/all/20261201155844.2278-5-ilpo.jarvinen@linux.intel.com/

-- 
 i.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-01 17:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261109210714.3862-1-ilpo.jarvinen@linux.intel.com>
2026-11-09 21:07 ` [PATCH 01/11] PCI: Free device name when pci_setup_device() fails Ilpo Järvinen
2026-11-09 21:07 ` [PATCH 02/11] PCI: Use Header Type in __pci_bridge_assign_resources() Ilpo Järvinen
2026-12-01 17:18   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox