Skip to content

Commit 18f9e9d

Browse files
sebottbjorn-helgaas
authored andcommitted
PCI/IOV: Factor out sriov_add_vfs()
Provide sriov_add_vfs() as a wrapper to scan for VFs that cleans up after itself. This is just a code simplification. No functional change. Signed-off-by: Sebastian Ott <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 6510223 commit 18f9e9d

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

drivers/pci/iov.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,24 @@ int __weak pcibios_sriov_disable(struct pci_dev *pdev)
252252
return 0;
253253
}
254254

255+
static int sriov_add_vfs(struct pci_dev *dev, u16 num_vfs)
256+
{
257+
unsigned int i;
258+
int rc;
259+
260+
for (i = 0; i < num_vfs; i++) {
261+
rc = pci_iov_add_virtfn(dev, i);
262+
if (rc)
263+
goto failed;
264+
}
265+
return 0;
266+
failed:
267+
while (i--)
268+
pci_iov_remove_virtfn(dev, i);
269+
270+
return rc;
271+
}
272+
255273
static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
256274
{
257275
int rc;
@@ -337,21 +355,15 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
337355
msleep(100);
338356
pci_cfg_access_unlock(dev);
339357

340-
for (i = 0; i < initial; i++) {
341-
rc = pci_iov_add_virtfn(dev, i);
342-
if (rc)
343-
goto failed;
344-
}
358+
rc = sriov_add_vfs(dev, initial);
359+
if (rc)
360+
goto err_pcibios;
345361

346362
kobject_uevent(&dev->dev.kobj, KOBJ_CHANGE);
347363
iov->num_VFs = nr_virtfn;
348364

349365
return 0;
350366

351-
failed:
352-
while (i--)
353-
pci_iov_remove_virtfn(dev, i);
354-
355367
err_pcibios:
356368
iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
357369
pci_cfg_access_lock(dev);
@@ -368,17 +380,23 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
368380
return rc;
369381
}
370382

371-
static void sriov_disable(struct pci_dev *dev)
383+
static void sriov_del_vfs(struct pci_dev *dev)
372384
{
385+
struct pci_sriov *iov = dev->sriov;
373386
int i;
387+
388+
for (i = 0; i < iov->num_VFs; i++)
389+
pci_iov_remove_virtfn(dev, i);
390+
}
391+
392+
static void sriov_disable(struct pci_dev *dev)
393+
{
374394
struct pci_sriov *iov = dev->sriov;
375395

376396
if (!iov->num_VFs)
377397
return;
378398

379-
for (i = 0; i < iov->num_VFs; i++)
380-
pci_iov_remove_virtfn(dev, i);
381-
399+
sriov_del_vfs(dev);
382400
iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
383401
pci_cfg_access_lock(dev);
384402
pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);

0 commit comments

Comments
 (0)