Re: [PATCH] PCI: pciehp: Fix NULL pointer dereference in pciehp_configure_device()

From: Priyank Rathod

Date: Mon Nov 09 2026 - 16:56:03 EST


On Mon, Oct 12, 2026 at 10:16:29PM +0000, sashiko-bot@xxxxxxxxxx wrote:
> While this allows devices without Function 0 to be successfully hot-added,
> will it lead to spurious teardowns upon system resume?
...
> Could this spurious teardown issue be avoided by modifying
> pciehp_device_replaced() to handle missing Function 0 devices correctly?

Hi Bjorn, Lukas,

Gentle ping on this fix now that v7.4-rc1 is out (the patch still
applies cleanly to v7.4-rc1 and pci/next).

Regarding the bot's question above: pciehp assumes Function 0
(PCI_DEVFN(0, 0)) represents an occupied slot across all four of its
lookup sites -- the -EEXIST check at the top of
pciehp_configure_device(), pcie_init(), pciehp_device_replaced(), and
the DSN read at the end of pciehp_configure_device() (consistent with
PCIe r6.3 sec 7.9.3 requiring Multi-Function Devices implementing DSN to
expose it on Function 0).

I intentionally kept this patch scoped strictly to the missing NULL
check in pciehp_configure_device() -- the only unchecked pci_get_slot()
call in pciehp -- rather than mixing a broader change to pciehp's
pre-existing Function 0 behavior into a minimal NULL-dereference fix.

Please let me know which direction you prefer: taking this minimal NULL
check fix standalone as-is, and whether you think handling isolated
non-zero functions in pciehp_device_replaced() (and the other
PCI_DEVFN(0, 0) sites) is worth pursuing as a separate follow-up or best
left anchored to Function 0.

Thanks,
Priyank