Skip to content

Commit

Permalink
net: aquantia: Fix error handling in aq_pci_probe()
Browse files Browse the repository at this point in the history
We should check "self->aq_hw" for allocation failure, and also we should
free it on the error paths.

Fixes: 23ee07a ("net: aquantia: Cleanup pci functions module")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Dan Carpenter authored and David S. Miller committed Feb 22, 2018
1 parent ed04c46 commit 370c105
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ static int aq_pci_probe(struct pci_dev *pdev,
goto err_ioremap;

self->aq_hw = kzalloc(sizeof(*self->aq_hw), GFP_KERNEL);
if (!self->aq_hw) {
err = -ENOMEM;
goto err_ioremap;
}
self->aq_hw->aq_nic_cfg = aq_nic_get_cfg(self);

for (bar = 0; bar < 4; ++bar) {
Expand All @@ -235,27 +239,27 @@ static int aq_pci_probe(struct pci_dev *pdev,
mmio_pa = pci_resource_start(pdev, bar);
if (mmio_pa == 0U) {
err = -EIO;
goto err_ioremap;
goto err_free_aq_hw;
}

reg_sz = pci_resource_len(pdev, bar);
if ((reg_sz <= 24 /*ATL_REGS_SIZE*/)) {
err = -EIO;
goto err_ioremap;
goto err_free_aq_hw;
}

self->aq_hw->mmio = ioremap_nocache(mmio_pa, reg_sz);
if (!self->aq_hw->mmio) {
err = -EIO;
goto err_ioremap;
goto err_free_aq_hw;
}
break;
}
}

if (bar == 4) {
err = -EIO;
goto err_ioremap;
goto err_free_aq_hw;
}

numvecs = min((u8)AQ_CFG_VECS_DEF,
Expand Down Expand Up @@ -290,6 +294,8 @@ static int aq_pci_probe(struct pci_dev *pdev,
aq_pci_free_irq_vectors(self);
err_hwinit:
iounmap(self->aq_hw->mmio);
err_free_aq_hw:
kfree(self->aq_hw);
err_ioremap:
free_netdev(ndev);
err_pci_func:
Expand Down

0 comments on commit 370c105

Please sign in to comment.