b43legacy: fix DMA slot resource leakage
[safe/jmp/linux-2.6] / drivers / net / tulip / de2104x.c
index 5f743b9..77d9dd7 100644 (file)
@@ -31,7 +31,6 @@
 #define DRV_VERSION            "0.7"
 #define DRV_RELDATE            "Mar 17, 2004"
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
@@ -64,7 +63,7 @@ MODULE_PARM_DESC (debug, "de2104x bitmapped message enable number");
 
 /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
 #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
-        || defined(__sparc_) || defined(__ia64__) \
+        || defined(CONFIG_SPARC) || defined(__ia64__) \
         || defined(__sh__) || defined(__mips__)
 static int rx_copybreak = 1518;
 #else
@@ -265,10 +264,10 @@ struct de_srom_info_leaf {
 } __attribute__((packed));
 
 struct de_desc {
-       u32                     opts1;
-       u32                     opts2;
-       u32                     addr1;
-       u32                     addr2;
+       __le32                  opts1;
+       __le32                  opts2;
+       __le32                  addr1;
+       __le32                  addr2;
 };
 
 struct media_info {
@@ -436,7 +435,6 @@ static void de_rx (struct de_private *de)
                        rx_work = 100;
                        goto rx_next;
                }
-               copy_skb->dev = de->dev;
 
                if (!copying_skb) {
                        pci_unmap_single(de->pdev, mapping,
@@ -451,8 +449,8 @@ static void de_rx (struct de_private *de)
                } else {
                        pci_dma_sync_single_for_cpu(de->pdev, mapping, len, PCI_DMA_FROMDEVICE);
                        skb_reserve(copy_skb, RX_OFFSET);
-                       memcpy(skb_put(copy_skb, len), skb->data, len);
-
+                       skb_copy_from_linear_data(skb, skb_put(copy_skb, len),
+                                                 len);
                        pci_dma_sync_single_for_device(de->pdev, mapping, len, PCI_DMA_FROMDEVICE);
 
                        /* We'll reuse the original ring buffer. */
@@ -485,7 +483,7 @@ rx_next:
        de->rx_tail = rx_tail;
 }
 
-static irqreturn_t de_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
+static irqreturn_t de_interrupt (int irq, void *dev_instance)
 {
        struct net_device *dev = dev_instance;
        struct de_private *de = dev->priv;
@@ -787,7 +785,6 @@ static void __de_set_rx_mode (struct net_device *dev)
 
        de->tx_head = NEXT_TX(entry);
 
-       BUG_ON(TX_BUFFS_AVAIL(de) < 0);
        if (TX_BUFFS_AVAIL(de) == 0)
                netif_stop_queue(dev);
 
@@ -1372,7 +1369,7 @@ static int de_open (struct net_device *dev)
 
        dw32(IntrMask, 0);
 
-       rc = request_irq(dev->irq, de_interrupt, SA_SHIRQ, dev->name, dev);
+       rc = request_irq(dev->irq, de_interrupt, IRQF_SHARED, dev->name, dev);
        if (rc) {
                printk(KERN_ERR "%s: IRQ %d request failure, err=%d\n",
                       dev->name, dev->irq, rc);
@@ -1671,10 +1668,8 @@ static void de_get_regs(struct net_device *dev, struct ethtool_regs *regs,
        spin_unlock_irq(&de->lock);
 }
 
-static struct ethtool_ops de_ethtool_ops = {
+static const struct ethtool_ops de_ethtool_ops = {
        .get_link               = ethtool_op_get_link,
-       .get_tx_csum            = ethtool_op_get_tx_csum,
-       .get_sg                 = ethtool_op_get_sg,
        .get_drvinfo            = de_get_drvinfo,
        .get_regs_len           = de_get_regs_len,
        .get_settings           = de_get_settings,
@@ -1686,7 +1681,7 @@ static struct ethtool_ops de_ethtool_ops = {
        .get_regs               = de_get_regs,
 };
 
-static void __init de21040_get_mac_address (struct de_private *de)
+static void __devinit de21040_get_mac_address (struct de_private *de)
 {
        unsigned i;
 
@@ -1704,7 +1699,7 @@ static void __init de21040_get_mac_address (struct de_private *de)
        }
 }
 
-static void __init de21040_get_media_info(struct de_private *de)
+static void __devinit de21040_get_media_info(struct de_private *de)
 {
        unsigned int i;
 
@@ -1731,7 +1726,7 @@ static void __init de21040_get_media_info(struct de_private *de)
 }
 
 /* Note: this routine returns extra data bits for size detection. */
-static unsigned __init tulip_read_eeprom(void __iomem *regs, int location, int addr_len)
+static unsigned __devinit tulip_read_eeprom(void __iomem *regs, int location, int addr_len)
 {
        int i;
        unsigned retval = 0;
@@ -1766,7 +1761,7 @@ static unsigned __init tulip_read_eeprom(void __iomem *regs, int location, int a
        return retval;
 }
 
-static void __init de21041_get_srom_info (struct de_private *de)
+static void __devinit de21041_get_srom_info (struct de_private *de)
 {
        unsigned i, sa_offset = 0, ofs;
        u8 ee_data[DE_EEPROM_SIZE + 6] = {};
@@ -1776,8 +1771,8 @@ static void __init de21041_get_srom_info (struct de_private *de)
 
        /* download entire eeprom */
        for (i = 0; i < DE_EEPROM_WORDS; i++)
-               ((u16 *)ee_data)[i] =
-                       le16_to_cpu(tulip_read_eeprom(de->regs, i, ee_addr_size));
+               ((__le16 *)ee_data)[i] =
+                       cpu_to_le16(tulip_read_eeprom(de->regs, i, ee_addr_size));
 
        /* DEC now has a specification but early board makers
           just put the address in the first EEPROM locations. */
@@ -1907,9 +1902,7 @@ fill_defaults:
                        de->media[i].csr15 = t21041_csr15[i];
        }
 
-       de->ee_data = kmalloc(DE_EEPROM_SIZE, GFP_KERNEL);
-       if (de->ee_data)
-               memcpy(de->ee_data, &ee_data[0], DE_EEPROM_SIZE);
+       de->ee_data = kmemdup(&ee_data[0], DE_EEPROM_SIZE, GFP_KERNEL);
 
        return;
 
@@ -1927,7 +1920,7 @@ bad_srom:
        goto fill_defaults;
 }
 
-static int __init de_init_one (struct pci_dev *pdev,
+static int __devinit de_init_one (struct pci_dev *pdev,
                                  const struct pci_device_id *ent)
 {
        struct net_device *dev;
@@ -1936,6 +1929,7 @@ static int __init de_init_one (struct pci_dev *pdev,
        void __iomem *regs;
        unsigned long pciaddr;
        static int board_idx = -1;
+       DECLARE_MAC_BUF(mac);
 
        board_idx++;
 
@@ -1949,7 +1943,6 @@ static int __init de_init_one (struct pci_dev *pdev,
        if (!dev)
                return -ENOMEM;
 
-       SET_MODULE_OWNER(dev);
        SET_NETDEV_DEV(dev, &pdev->dev);
        dev->open = de_open;
        dev->stop = de_close;
@@ -2007,8 +2000,8 @@ static int __init de_init_one (struct pci_dev *pdev,
        }
        if (pci_resource_len(pdev, 1) < DE_REGS_SIZE) {
                rc = -EIO;
-               printk(KERN_ERR PFX "MMIO resource (%lx) too small on pci dev %s\n",
-                      pci_resource_len(pdev, 1), pci_name(pdev));
+               printk(KERN_ERR PFX "MMIO resource (%llx) too small on pci dev %s\n",
+                      (unsigned long long)pci_resource_len(pdev, 1), pci_name(pdev));
                goto err_out_res;
        }
 
@@ -2016,8 +2009,9 @@ static int __init de_init_one (struct pci_dev *pdev,
        regs = ioremap_nocache(pciaddr, DE_REGS_SIZE);
        if (!regs) {
                rc = -EIO;
-               printk(KERN_ERR PFX "Cannot map PCI MMIO (%lx@%lx) on pci dev %s\n",
-                      pci_resource_len(pdev, 1), pciaddr, pci_name(pdev));
+               printk(KERN_ERR PFX "Cannot map PCI MMIO (%llx@%lx) on pci dev %s\n",
+                       (unsigned long long)pci_resource_len(pdev, 1),
+                       pciaddr, pci_name(pdev));
                goto err_out_res;
        }
        dev->base_addr = (unsigned long) regs;
@@ -2049,15 +2043,11 @@ static int __init de_init_one (struct pci_dev *pdev,
                goto err_out_iomap;
 
        /* print info about board and interface just registered */
-       printk (KERN_INFO "%s: %s at 0x%lx, "
-               "%02x:%02x:%02x:%02x:%02x:%02x, "
-               "IRQ %d\n",
+       printk (KERN_INFO "%s: %s at 0x%lx, %s, IRQ %d\n",
                dev->name,
                de->de21040 ? "21040" : "21041",
                dev->base_addr,
-               dev->dev_addr[0], dev->dev_addr[1],
-               dev->dev_addr[2], dev->dev_addr[3],
-               dev->dev_addr[4], dev->dev_addr[5],
+               print_mac(mac, dev->dev_addr),
                dev->irq);
 
        pci_set_drvdata(pdev, dev);
@@ -2082,7 +2072,7 @@ err_out_free:
        return rc;
 }
 
-static void __exit de_remove_one (struct pci_dev *pdev)
+static void __devexit de_remove_one (struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata(pdev);
        struct de_private *de = dev->priv;
@@ -2138,17 +2128,21 @@ static int de_resume (struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata (pdev);
        struct de_private *de = dev->priv;
+       int retval = 0;
 
        rtnl_lock();
        if (netif_device_present(dev))
                goto out;
-       if (netif_running(dev)) {
-               pci_enable_device(pdev);
-               de_init_hw(de);
-               netif_device_attach(dev);
-       } else {
-               netif_device_attach(dev);
+       if (!netif_running(dev))
+               goto out_attach;
+       if ((retval = pci_enable_device(pdev))) {
+               printk (KERN_ERR "%s: pci_enable_device failed in resume\n",
+                       dev->name);
+               goto out;
        }
+       de_init_hw(de);
+out_attach:
+       netif_device_attach(dev);
 out:
        rtnl_unlock();
        return 0;
@@ -2160,7 +2154,7 @@ static struct pci_driver de_driver = {
        .name           = DRV_NAME,
        .id_table       = de_pci_tbl,
        .probe          = de_init_one,
-       .remove         = __exit_p(de_remove_one),
+       .remove         = __devexit_p(de_remove_one),
 #ifdef CONFIG_PM
        .suspend        = de_suspend,
        .resume         = de_resume,
@@ -2172,7 +2166,7 @@ static int __init de_init (void)
 #ifdef MODULE
        printk("%s", version);
 #endif
-       return pci_module_init (&de_driver);
+       return pci_register_driver(&de_driver);
 }
 
 static void __exit de_exit (void)