Skip to content

Commit d6ce262

Browse files
Hariprasad Shenaidavem330
authored andcommitted
cxgb4: Don't allocate adapter structure for all PF's
commit 35b1de5 ("rdma/cxgb4: Fixes cxgb4 probe failure in VM when PF is exposed through PCI Passthrough") moved the code to check for SR-IOV PF[0..3] much further down in init_one() past the point where we allocate a (struct adapter) for PF[0..3]. As a result, we left four of these on ever module remove. Fix: Allocate adapter structure only for PF4 Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c095f24 commit d6ce262

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6478,6 +6478,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
64786478
struct port_info *pi;
64796479
bool highdma = false;
64806480
struct adapter *adapter = NULL;
6481+
void __iomem *regs;
64816482

64826483
printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
64836484

@@ -6494,19 +6495,35 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
64946495
goto out_release_regions;
64956496
}
64966497

6498+
regs = pci_ioremap_bar(pdev, 0);
6499+
if (!regs) {
6500+
dev_err(&pdev->dev, "cannot map device registers\n");
6501+
err = -ENOMEM;
6502+
goto out_disable_device;
6503+
}
6504+
6505+
/* We control everything through one PF */
6506+
func = SOURCEPF_GET(readl(regs + PL_WHOAMI));
6507+
if (func != ent->driver_data) {
6508+
iounmap(regs);
6509+
pci_disable_device(pdev);
6510+
pci_save_state(pdev); /* to restore SR-IOV later */
6511+
goto sriov;
6512+
}
6513+
64976514
if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
64986515
highdma = true;
64996516
err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
65006517
if (err) {
65016518
dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
65026519
"coherent allocations\n");
6503-
goto out_disable_device;
6520+
goto out_unmap_bar0;
65046521
}
65056522
} else {
65066523
err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
65076524
if (err) {
65086525
dev_err(&pdev->dev, "no usable DMA configuration\n");
6509-
goto out_disable_device;
6526+
goto out_unmap_bar0;
65106527
}
65116528
}
65126529

@@ -6518,7 +6535,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
65186535
adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
65196536
if (!adapter) {
65206537
err = -ENOMEM;
6521-
goto out_disable_device;
6538+
goto out_unmap_bar0;
65226539
}
65236540

65246541
adapter->workq = create_singlethread_workqueue("cxgb4");
@@ -6530,20 +6547,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
65306547
/* PCI device has been enabled */
65316548
adapter->flags |= DEV_ENABLED;
65326549

6533-
adapter->regs = pci_ioremap_bar(pdev, 0);
6534-
if (!adapter->regs) {
6535-
dev_err(&pdev->dev, "cannot map device registers\n");
6536-
err = -ENOMEM;
6537-
goto out_free_adapter;
6538-
}
6539-
6540-
/* We control everything through one PF */
6541-
func = SOURCEPF_GET(readl(adapter->regs + PL_WHOAMI));
6542-
if (func != ent->driver_data) {
6543-
pci_save_state(pdev); /* to restore SR-IOV later */
6544-
goto sriov;
6545-
}
6546-
6550+
adapter->regs = regs;
65476551
adapter->pdev = pdev;
65486552
adapter->pdev_dev = &pdev->dev;
65496553
adapter->mbox = func;
@@ -6560,7 +6564,8 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
65606564

65616565
err = t4_prep_adapter(adapter);
65626566
if (err)
6563-
goto out_unmap_bar0;
6567+
goto out_free_adapter;
6568+
65646569

65656570
if (!is_t4(adapter->params.chip)) {
65666571
s_qpp = QUEUESPERPAGEPF1 * adapter->fn;
@@ -6577,14 +6582,14 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
65776582
dev_err(&pdev->dev,
65786583
"Incorrect number of egress queues per page\n");
65796584
err = -EINVAL;
6580-
goto out_unmap_bar0;
6585+
goto out_free_adapter;
65816586
}
65826587
adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
65836588
pci_resource_len(pdev, 2));
65846589
if (!adapter->bar2) {
65856590
dev_err(&pdev->dev, "cannot map device bar2 region\n");
65866591
err = -ENOMEM;
6587-
goto out_unmap_bar0;
6592+
goto out_free_adapter;
65886593
}
65896594
}
65906595

@@ -6722,13 +6727,13 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
67226727
out_unmap_bar:
67236728
if (!is_t4(adapter->params.chip))
67246729
iounmap(adapter->bar2);
6725-
out_unmap_bar0:
6726-
iounmap(adapter->regs);
67276730
out_free_adapter:
67286731
if (adapter->workq)
67296732
destroy_workqueue(adapter->workq);
67306733

67316734
kfree(adapter);
6735+
out_unmap_bar0:
6736+
iounmap(regs);
67326737
out_disable_device:
67336738
pci_disable_pcie_error_reporting(pdev);
67346739
pci_disable_device(pdev);

0 commit comments

Comments
 (0)