- missing pci_disable_device() in the pci probe/remove functions; - ioremap can fail; - let's propagate the error codes instead of overriding these; - velocity_free_info() removed. Non void velocity_get_pci_info() probably deserves an explanation but I do not have one :o) net/via-velocity.h | 0 drivers/net/via-velocity.c | 81 ++++++++++++++++++--------------------------- 2 files changed, 34 insertions(+), 47 deletions(-) diff -puN drivers/net/via-velocity.c~via-velocity-00 drivers/net/via-velocity.c --- linux-2.6.6-mm4/drivers/net/via-velocity.c~via-velocity-00 2004-05-31 21:07:14.000000000 +0200 +++ linux-2.6.6-mm4-fr/drivers/net/via-velocity.c 2004-05-31 21:31:16.000000000 +0200 @@ -244,7 +244,6 @@ VELOCITY_PARAM(int_works, "Number of pac static int velocity_found1(struct pci_dev *pdev, const struct pci_device_id *ent); static void velocity_init_info(struct pci_dev *pdev, struct velocity_info *vptr, struct velocity_info_tbl *info); -static void velocity_free_info(struct velocity_info *vptr); static int velocity_get_pci_info(struct velocity_info *, struct pci_dev *pdev); static void velocity_print_info(struct velocity_info *vptr); static int velocity_open(struct net_device *dev); @@ -341,11 +340,13 @@ static void __devexit velocity_remove1(s { struct net_device *dev = pci_get_drvdata(pdev); struct velocity_info *vptr = dev->priv; + unregister_netdev(dev); - velocity_free_info(vptr); + iounmap(vptr->mac_regs); pci_release_regions(pdev); + pci_disable_device(pdev); + pci_set_drvdata(pdev, NULL); free_netdev(dev); - } /** @@ -674,6 +675,7 @@ static int velocity_found1(struct pci_de struct velocity_info_tbl *info = (struct velocity_info_tbl *) ent->driver_data; struct velocity_info *vptr; struct mac_regs * regs; + int ret = -ENOMEM; if (velocity_nics++ >= MAX_UNITS) { printk(KERN_NOTICE VELOCITY_NAME ": already found %d NICs.\n", @@ -685,7 +687,7 @@ static int velocity_found1(struct pci_de if (dev == NULL) { printk(KERN_ERR VELOCITY_NAME ": allocate net device failed.\n"); - return -ENODEV; + goto out; } /* Chain it all together */ @@ -710,28 +712,28 @@ static int velocity_found1(struct pci_de dev->priv = vptr; dev->irq = pdev->irq; - if (pci_enable_device(pdev)) { - velocity_free_info(vptr); - free_netdev(dev); - return -ENODEV; - } + ret = pci_enable_device(pdev); + if (ret < 0) + goto err_free_dev; - if (velocity_get_pci_info(vptr, pdev) < 0) { + ret = velocity_get_pci_info(vptr, pdev); + if (ret < 0) { printk(KERN_ERR VELOCITY_NAME ": Failed to find PCI device.\n"); - velocity_free_info(vptr); - free_netdev(dev); - return -ENODEV; + goto err_disable; } - if ((i = pci_request_regions(pdev, VELOCITY_NAME)) < 0) { + ret = pci_request_regions(pdev, VELOCITY_NAME); + if (ret < 0) { printk(KERN_ERR VELOCITY_NAME ": Failed to find PCI device.\n"); - vptr->ioaddr = 0; - velocity_free_info(vptr); - free_netdev(dev); - return i; + goto err_disable; } regs = ioremap(vptr->memaddr, vptr->io_size); + if (regs == NULL) { + ret = -EIO; + goto err_release_res; + } + vptr->mac_regs = regs; mac_wol_reset(regs); @@ -778,14 +780,9 @@ static int velocity_found1(struct pci_de dev->features |= NETIF_F_HW_CSUM; } - i = register_netdev (dev); - if (i) - { - pci_release_regions(pdev); - velocity_free_info(vptr); - free_netdev(dev); - return i; - } + ret = register_netdev(dev); + if (ret < 0) + goto err_iounmap; velocity_print_info(vptr); pci_set_drvdata(pdev, dev); @@ -793,8 +790,18 @@ static int velocity_found1(struct pci_de /* and leave the chip powered down */ pci_set_power_state(pdev, 3); +out: + return ret; - return 0; +err_iounmap: + iounmap(regs); +err_release_res: + pci_release_regions(pdev); +err_disable: + pci_disable_device(pdev); +err_free_dev: + free_netdev(dev); + goto out; } /** @@ -864,26 +871,6 @@ static int velocity_get_pci_info(struct } /** - * velocity_free_info - free velocity data - * @vptr: velocity - * - * Free up the data structures for the velocity hardware - * that we are unloading. Relies on the PCI layer threading/locking - * rather than its own locks. Must not be called until the device - * is unplugged from the network layer - */ - -static void velocity_free_info(struct velocity_info *vptr) -{ - ASSERT(vptr); - if (vptr->mac_regs) - iounmap(vptr->mac_regs); - if (vptr->pdev) { - pci_set_drvdata(vptr->pdev, NULL); - } -} - -/** * velocity_init_rings - set up DMA rings * @vptr: Velocity to set up * diff -puN drivers/net/via-velocity.h~via-velocity-00 drivers/net/via-velocity.h _