The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Yuho Choi <dbgh9129@gmail.com>
To: bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yuho Choi <dbgh9129@gmail.com>
Subject: [PATCH v1] PCI: Release SR-IOV device reference on init failure
Date: Thu,  6 Aug 2026 22:20:25 -0400	[thread overview]
Message-ID: <20260807022025.921764-1-dbgh9129@gmail.com> (raw)

sriov_init() takes a reference on the sibling physical function stored in
pci_sriov->dev before computing the maximum VF bus usage. If
compute_max_vf_buses() fails, the failure path clears the SR-IOV state and
frees pci_sriov without releasing that reference. Since is_physfn is
cleared, pci_iov_release() cannot clean it up later.

Release the reference on the failure path when pci_sriov->dev is different
from the device being initialized, matching the cleanup in sriov_release().

Fixes: ea9a8854161d ("PCI: Set SR-IOV NumVFs to zero after enumeration")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
---
 drivers/pci/iov.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index b0d24839c084..65c60f88a3d4 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -907,6 +907,8 @@ static int sriov_init(struct pci_dev *dev, int pos)
 fail_max_buses:
 	dev->sriov = NULL;
 	dev->is_physfn = 0;
+	if (iov->dev != dev)
+		pci_dev_put(iov->dev);
 failed:
 	for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
 		res = &dev->resource[pci_resource_num_from_vf_bar(i)];
-- 
2.43.0


                 reply	other threads:[~2026-08-07  2:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260807022025.921764-1-dbgh9129@gmail.com \
    --to=dbgh9129@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@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