Skip to contentSkip to conversation

PCI: Release SR-IOV device reference on init failure

PATCH New Yuho Choi 2 participants 2 messages Aug 7 PCI

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 PCI: Release SR-IOV device reference on init failure

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")
---
 drivers/pci/iov.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/iov.c +2 -0
index b0d24839c084..65c60f88a3d4 100644
@@ -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)];
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

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")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1