diff mbox series

PCI: Cleanup SR-IOV state on unsuccessful PF driver probe

Message ID 20240715102835.1286-1-michal.wajdeczko@intel.com (mailing list archive)
State New
Delegated to: Bjorn Helgaas
Headers show
Series PCI: Cleanup SR-IOV state on unsuccessful PF driver probe | expand

Commit Message

Michal Wajdeczko July 15, 2024, 10:28 a.m. UTC
During the probe, the PF driver might call pci_sriov_set_totalvfs()
to reduce the number of supported VFs. This will be restored later
by the PCI layer when the PF driver is detached.

In rare cases, when the PF driver fails the .probe routine after
it reduced the number of supported VFs, the value of TotalVFs will
not be restored automatically. This may impact subsequent probe
attempts as next calls to pci_sriov_get_totalvfs() will return an
already modified value.

To avoid this issue, either we should expect that all PF drivers
will restore TotalVFs on its own before failing the probe, or we
can do some explicit cleanup inside the PCI layer. Since the
latter case seems to be trivial to implement, let's start with it.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org
---
 drivers/pci/pci-driver.c | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index af2996d0d17f..c949fdd09f26 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -326,6 +326,7 @@  static long local_pci_probe(void *_ddi)
 		return rc;
 	if (rc < 0) {
 		pci_dev->driver = NULL;
+		pci_iov_remove(pci_dev);
 		pm_runtime_put_sync(dev);
 		return rc;
 	}