From: sashiko-bot@kernel.org
To: "Priyank Rathod" <rathodpriyank@google.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI: pciehp: Fix NULL pointer dereference in pciehp_configure_device()
Date: Mon, 12 Oct 2026 22:16:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-168676@kernel.org> (raw)
In-Reply-To: <20261012-pcie-hotplug-nullref-v1-1-6e21c2e89ea4@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] pciehp: spurious device teardown on resume for devices lacking Function 0
--
commit 26f6592be4bd1ee27e178fdf85798fa2b65a389a
Author: Priyank Rathod <rathodpriyank@google.com>
PCI: pciehp: Fix NULL pointer dereference in pciehp_configure_device()
This commit fixes a NULL pointer dereference in pciehp_configure_device()
when attempting to read the DSN of a newly hot-added device. By guarding the
pci_get_dsn() call against a missing Function 0, it allows devices lacking
Function 0 (such as those under hypervisor isolation) to be successfully
hot-added.
> diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c
> index 65e50bee1a8c0..5f9e8044ea5be 100644
> --- a/drivers/pci/hotplug/pciehp_pci.c
> +++ b/drivers/pci/hotplug/pciehp_pci.c
> @@ -73,7 +73,7 @@ int pciehp_configure_device(struct controller *ctrl)
> down_read_nested(&ctrl->reset_lock, ctrl->depth);
>
> dev = pci_get_slot(parent, PCI_DEVFN(0, 0));
> - ctrl->dsn = pci_get_dsn(dev);
> + ctrl->dsn = dev ? pci_get_dsn(dev) : 0;
[Severity: Medium]
While this allows devices without Function 0 to be successfully hot-added,
will it lead to spurious teardowns upon system resume?
When the system resumes, pciehp_resume_noirq() calls pciehp_device_replaced().
If a device legitimately lacks Function 0, pci_get_slot() for PCI_DEVFN(0, 0)
will return NULL:
drivers/pci/hotplug/pciehp_hpc.c:pciehp_device_replaced() {
...
pdev = pci_get_slot(ctrl->pcie->port->subordinate, PCI_DEVFN(0, 0));
if (!pdev)
return true;
...
}
Because it unconditionally returns true when Function 0 is absent, this false
replacement signal will trigger pci_walk_bus() to set the disconnected state
and queue a teardown request.
Could this spurious teardown issue be avoided by modifying
pciehp_device_replaced() to handle missing Function 0 devices correctly?
> pci_dev_put(dev);
>
> out:
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012-pcie-hotplug-nullref-v1-1-6e21c2e89ea4@google.com?part=1
prev parent reply other threads:[~2026-10-12 22:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 22:03 [PATCH] PCI: pciehp: Fix NULL pointer dereference in pciehp_configure_device() Priyank Rathod
2026-10-12 22:16 ` sashiko-bot [this message]
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=sashiko-outbox-168676@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rathodpriyank@google.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.