Commit 7cb43beb authored by Amitoj Kaur Chawla's avatar Amitoj Kaur Chawla Committed by David S. Miller

wan: lmc: Switch to using managed resources

Use managed resource functions devm_kzalloc and pcim_enable_device
to simplify error handling. Subsequently, remove unnecessary
kfree, pci_disable_device and pci_release_regions.

To be compatible with the change, various gotos are replaced with
direct returns and unneeded labels are dropped.

Also, `sc` was only being freed in the probe function and not the
remove function before the change. By using devm_kzalloc this patch
also fixes this memory leak.
Signed-off-by: default avatarAmitoj Kaur Chawla <amitoj1606@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7da5ee09
...@@ -826,7 +826,7 @@ static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -826,7 +826,7 @@ static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
/* lmc_trace(dev, "lmc_init_one in"); */ /* lmc_trace(dev, "lmc_init_one in"); */
err = pci_enable_device(pdev); err = pcim_enable_device(pdev);
if (err) { if (err) {
printk(KERN_ERR "lmc: pci enable failed: %d\n", err); printk(KERN_ERR "lmc: pci enable failed: %d\n", err);
return err; return err;
...@@ -835,23 +835,20 @@ static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -835,23 +835,20 @@ static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
err = pci_request_regions(pdev, "lmc"); err = pci_request_regions(pdev, "lmc");
if (err) { if (err) {
printk(KERN_ERR "lmc: pci_request_region failed\n"); printk(KERN_ERR "lmc: pci_request_region failed\n");
goto err_req_io; return err;
} }
/* /*
* Allocate our own device structure * Allocate our own device structure
*/ */
sc = kzalloc(sizeof(lmc_softc_t), GFP_KERNEL); sc = devm_kzalloc(&pdev->dev, sizeof(lmc_softc_t), GFP_KERNEL);
if (!sc) { if (!sc)
err = -ENOMEM; return -ENOMEM;
goto err_kzalloc;
}
dev = alloc_hdlcdev(sc); dev = alloc_hdlcdev(sc);
if (!dev) { if (!dev) {
printk(KERN_ERR "lmc:alloc_netdev for device failed\n"); printk(KERN_ERR "lmc:alloc_netdev for device failed\n");
err = -ENOMEM; return -ENOMEM;
goto err_hdlcdev;
} }
...@@ -888,7 +885,7 @@ static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -888,7 +885,7 @@ static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
if (err) { if (err) {
printk(KERN_ERR "%s: register_netdev failed.\n", dev->name); printk(KERN_ERR "%s: register_netdev failed.\n", dev->name);
free_netdev(dev); free_netdev(dev);
goto err_hdlcdev; return err;
} }
sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN; sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN;
...@@ -971,14 +968,6 @@ static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -971,14 +968,6 @@ static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
lmc_trace(dev, "lmc_init_one out"); lmc_trace(dev, "lmc_init_one out");
return 0; return 0;
err_hdlcdev:
kfree(sc);
err_kzalloc:
pci_release_regions(pdev);
err_req_io:
pci_disable_device(pdev);
return err;
} }
/* /*
...@@ -992,8 +981,6 @@ static void lmc_remove_one(struct pci_dev *pdev) ...@@ -992,8 +981,6 @@ static void lmc_remove_one(struct pci_dev *pdev)
printk(KERN_DEBUG "%s: removing...\n", dev->name); printk(KERN_DEBUG "%s: removing...\n", dev->name);
unregister_hdlc_device(dev); unregister_hdlc_device(dev);
free_netdev(dev); free_netdev(dev);
pci_release_regions(pdev);
pci_disable_device(pdev);
} }
} }
......
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