Skip to content

Commit 914d9b2

Browse files
DerDakonkuba-moo
authored andcommitted
sunhme: switch to devres
This not only removes a lot of code, it also fixes the memleak of the DMA memory when register_netdev() fails. Signed-off-by: Rolf Eike Beer <[email protected]> [ rebased onto net-next/master; fixed error reporting ] Signed-off-by: Sean Anderson <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5b3dc6d commit 914d9b2

File tree

1 file changed

+14
-41
lines changed

1 file changed

+14
-41
lines changed

drivers/net/ethernet/sun/sunhme.c

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,7 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
29242924
struct happy_meal *hp;
29252925
struct net_device *dev;
29262926
void __iomem *hpreg_base;
2927-
unsigned long hpreg_res;
2927+
struct resource *hpreg_res;
29282928
int i, qfe_slot = -1;
29292929
char prom_name[64];
29302930
u8 addr[ETH_ALEN];
@@ -2941,7 +2941,7 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
29412941
strcpy(prom_name, "SUNW,hme");
29422942
#endif
29432943

2944-
err = pci_enable_device(pdev);
2944+
err = pcim_enable_device(pdev);
29452945
if (err)
29462946
goto err_out;
29472947
pci_set_master(pdev);
@@ -2961,7 +2961,7 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
29612961
goto err_out;
29622962
}
29632963

2964-
dev = alloc_etherdev(sizeof(struct happy_meal));
2964+
dev = devm_alloc_etherdev(&pdev->dev, sizeof(struct happy_meal));
29652965
if (!dev) {
29662966
err = -ENOMEM;
29672967
goto err_out;
@@ -2981,25 +2981,26 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
29812981
qp->happy_meals[qfe_slot] = dev;
29822982
}
29832983

2984-
hpreg_res = pci_resource_start(pdev, 0);
29852984
err = -EINVAL;
29862985
if ((pci_resource_flags(pdev, 0) & IORESOURCE_IO) != 0) {
29872986
printk(KERN_ERR "happymeal(PCI): Cannot find proper PCI device base address.\n");
29882987
goto err_out_clear_quattro;
29892988
}
29902989

2991-
err = pci_request_regions(pdev, DRV_NAME);
2992-
if (err) {
2990+
hpreg_res = devm_request_region(&pdev->dev, pci_resource_start(pdev, 0),
2991+
pci_resource_len(pdev, 0), DRV_NAME);
2992+
if (IS_ERR(hpreg_res)) {
2993+
err = PTR_ERR(hpreg_res);
29932994
printk(KERN_ERR "happymeal(PCI): Cannot obtain PCI resources, "
29942995
"aborting.\n");
29952996
goto err_out_clear_quattro;
29962997
}
29972998

2998-
hpreg_base = ioremap(hpreg_res, 0x8000);
2999+
hpreg_base = pcim_iomap(pdev, 0, 0x8000);
29993000
if (!hpreg_base) {
30003001
err = -ENOMEM;
30013002
printk(KERN_ERR "happymeal(PCI): Unable to remap card memory.\n");
3002-
goto err_out_free_res;
3003+
goto err_out_clear_quattro;
30033004
}
30043005

30053006
for (i = 0; i < 6; i++) {
@@ -3065,11 +3066,11 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
30653066
hp->happy_bursts = DMA_BURSTBITS;
30663067
#endif
30673068

3068-
hp->happy_block = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
3069-
&hp->hblock_dvma, GFP_KERNEL);
3069+
hp->happy_block = dmam_alloc_coherent(&pdev->dev, PAGE_SIZE,
3070+
&hp->hblock_dvma, GFP_KERNEL);
30703071
if (!hp->happy_block) {
30713072
err = -ENOMEM;
3072-
goto err_out_iounmap;
3073+
goto err_out_clear_quattro;
30733074
}
30743075

30753076
hp->linkcheck = 0;
@@ -3104,11 +3105,11 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
31043105
happy_meal_set_initial_advertisement(hp);
31053106
spin_unlock_irq(&hp->happy_lock);
31063107

3107-
err = register_netdev(hp->dev);
3108+
err = devm_register_netdev(&pdev->dev, dev);
31083109
if (err) {
31093110
printk(KERN_ERR "happymeal(PCI): Cannot register net device, "
31103111
"aborting.\n");
3111-
goto err_out_free_coherent;
3112+
goto err_out_clear_quattro;
31123113
}
31133114

31143115
pci_set_drvdata(pdev, hp);
@@ -3141,41 +3142,14 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
31413142

31423143
return 0;
31433144

3144-
err_out_free_coherent:
3145-
dma_free_coherent(hp->dma_dev, PAGE_SIZE,
3146-
hp->happy_block, hp->hblock_dvma);
3147-
3148-
err_out_iounmap:
3149-
iounmap(hp->gregs);
3150-
3151-
err_out_free_res:
3152-
pci_release_regions(pdev);
3153-
31543145
err_out_clear_quattro:
31553146
if (qp != NULL)
31563147
qp->happy_meals[qfe_slot] = NULL;
31573148

3158-
free_netdev(dev);
3159-
31603149
err_out:
31613150
return err;
31623151
}
31633152

3164-
static void happy_meal_pci_remove(struct pci_dev *pdev)
3165-
{
3166-
struct happy_meal *hp = pci_get_drvdata(pdev);
3167-
struct net_device *net_dev = hp->dev;
3168-
3169-
unregister_netdev(net_dev);
3170-
3171-
dma_free_coherent(hp->dma_dev, PAGE_SIZE,
3172-
hp->happy_block, hp->hblock_dvma);
3173-
iounmap(hp->gregs);
3174-
pci_release_regions(hp->happy_dev);
3175-
3176-
free_netdev(net_dev);
3177-
}
3178-
31793153
static const struct pci_device_id happymeal_pci_ids[] = {
31803154
{ PCI_DEVICE(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_HAPPYMEAL) },
31813155
{ } /* Terminating entry */
@@ -3187,7 +3161,6 @@ static struct pci_driver hme_pci_driver = {
31873161
.name = "hme",
31883162
.id_table = happymeal_pci_ids,
31893163
.probe = happy_meal_pci_probe,
3190-
.remove = happy_meal_pci_remove,
31913164
};
31923165

31933166
static int __init happy_meal_pci_init(void)

0 commit comments

Comments
 (0)