Commit 7ed4eb51 authored by Lino Sanfilippo's avatar Lino Sanfilippo Committed by Greg Kroah-Hartman

staging: slicoss: handle allocation failure in slic_init_adapter

The memory allocation in slic_init_adapter() can fail. Return an error in
this case and unwind properly. Also make sure that the allocated memory is
properly freed in case of an error in the calling probe() function.
By doing this also replace the alloc() followed by memset to zero the
memory with a zalloc() version.
Signed-off-by: default avatarLino Sanfilippo <LinoSanfilippo@gmx.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f56edd42
...@@ -2896,7 +2896,7 @@ static void slic_init_driver(void) ...@@ -2896,7 +2896,7 @@ static void slic_init_driver(void)
} }
} }
static void slic_init_adapter(struct net_device *netdev, static int slic_init_adapter(struct net_device *netdev,
struct pci_dev *pcidev, struct pci_dev *pcidev,
const struct pci_device_id *pci_tbl_entry, const struct pci_device_id *pci_tbl_entry,
void __iomem *memaddr, int chip_idx) void __iomem *memaddr, int chip_idx)
...@@ -2938,13 +2938,13 @@ static void slic_init_adapter(struct net_device *netdev, ...@@ -2938,13 +2938,13 @@ static void slic_init_adapter(struct net_device *netdev,
pslic_handle->next = adapter->pfree_slic_handles; pslic_handle->next = adapter->pfree_slic_handles;
adapter->pfree_slic_handles = pslic_handle; adapter->pfree_slic_handles = pslic_handle;
} }
adapter->pshmem = (struct slic_shmem *) adapter->pshmem = pci_zalloc_consistent(adapter->pcidev,
pci_alloc_consistent(adapter->pcidev,
sizeof(struct slic_shmem), sizeof(struct slic_shmem),
&adapter-> &adapter->phys_shmem);
phys_shmem); if (!adapter->pshmem)
if (adapter->pshmem) return -ENOMEM;
memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
return 0;
} }
static const struct net_device_ops slic_netdev_ops = { static const struct net_device_ops slic_netdev_ops = {
...@@ -3142,13 +3142,17 @@ static int slic_entry_probe(struct pci_dev *pcidev, ...@@ -3142,13 +3142,17 @@ static int slic_entry_probe(struct pci_dev *pcidev,
slic_init_driver(); slic_init_driver();
slic_init_adapter(netdev, err = slic_init_adapter(netdev, pcidev, pci_tbl_entry, memmapped_ioaddr,
pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found); cards_found);
if (err) {
dev_err(&pcidev->dev, "failed to init adapter: %i\n", err);
goto err_out_unmap;
}
err = slic_card_locate(adapter); err = slic_card_locate(adapter);
if (err) { if (err) {
dev_err(&pcidev->dev, "cannot locate card\n"); dev_err(&pcidev->dev, "cannot locate card\n");
goto err_out_unmap; goto err_clean_init;
} }
card = adapter->card; card = adapter->card;
...@@ -3160,7 +3164,7 @@ static int slic_entry_probe(struct pci_dev *pcidev, ...@@ -3160,7 +3164,7 @@ static int slic_entry_probe(struct pci_dev *pcidev,
err = slic_card_init(card, adapter); err = slic_card_init(card, adapter);
if (err) if (err)
goto err_out_unmap; goto err_clean_init;
slic_adapter_set_hwaddr(adapter); slic_adapter_set_hwaddr(adapter);
...@@ -3172,13 +3176,15 @@ static int slic_entry_probe(struct pci_dev *pcidev, ...@@ -3172,13 +3176,15 @@ static int slic_entry_probe(struct pci_dev *pcidev,
err = register_netdev(netdev); err = register_netdev(netdev);
if (err) { if (err) {
dev_err(&pcidev->dev, "Cannot register net device, aborting.\n"); dev_err(&pcidev->dev, "Cannot register net device, aborting.\n");
goto err_out_unmap; goto err_clean_init;
} }
cards_found++; cards_found++;
return 0; return 0;
err_clean_init:
slic_init_cleanup(adapter);
err_out_unmap: err_out_unmap:
iounmap(memmapped_ioaddr); iounmap(memmapped_ioaddr);
err_out_free_netdev: err_out_free_netdev:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment