aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/e1000
diff options
context:
space:
mode:
authorYan Burman <burman.yan@gmail.com>2007-03-06 11:58:04 -0500
committerJeff Garzik <jeff@garzik.org>2007-04-28 11:00:57 -0400
commit1c7e5b125a0d31efd994326ed4c6d60c5760c43b (patch)
tree5cbedd5e8a8ebf7aaf5eb0157c29b574a84cbbe2 /drivers/net/e1000
parentc38db30b22913394f4634dc09f32d7838eb52ca1 (diff)
e1000: Use kcalloc()
Replace kmalloc+memsetout the driver. Slightly modified by Auke Kok. Signed-off-by: Yan Burman <burman.yan@gmail.com> Signed-off-by: Auke Kok <auke-jan.h.kok@intel.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/net/e1000')
-rw-r--r--drivers/net/e1000/e1000_ethtool.c26
-rw-r--r--drivers/net/e1000/e1000_main.c29
2 files changed, 24 insertions, 31 deletions
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index a094288f0277..2881da1c6fe3 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -654,14 +654,11 @@ e1000_set_ringparam(struct net_device *netdev,
654 e1000_mac_type mac_type = adapter->hw.mac_type; 654 e1000_mac_type mac_type = adapter->hw.mac_type;
655 struct e1000_tx_ring *txdr, *tx_old; 655 struct e1000_tx_ring *txdr, *tx_old;
656 struct e1000_rx_ring *rxdr, *rx_old; 656 struct e1000_rx_ring *rxdr, *rx_old;
657 int i, err, tx_ring_size, rx_ring_size; 657 int i, err;
658 658
659 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 659 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
660 return -EINVAL; 660 return -EINVAL;
661 661
662 tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
663 rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
664
665 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) 662 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
666 msleep(1); 663 msleep(1);
667 664
@@ -672,11 +669,11 @@ e1000_set_ringparam(struct net_device *netdev,
672 rx_old = adapter->rx_ring; 669 rx_old = adapter->rx_ring;
673 670
674 err = -ENOMEM; 671 err = -ENOMEM;
675 txdr = kzalloc(tx_ring_size, GFP_KERNEL); 672 txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring), GFP_KERNEL);
676 if (!txdr) 673 if (!txdr)
677 goto err_alloc_tx; 674 goto err_alloc_tx;
678 675
679 rxdr = kzalloc(rx_ring_size, GFP_KERNEL); 676 rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring), GFP_KERNEL);
680 if (!rxdr) 677 if (!rxdr)
681 goto err_alloc_rx; 678 goto err_alloc_rx;
682 679
@@ -1053,23 +1050,24 @@ e1000_setup_desc_rings(struct e1000_adapter *adapter)
1053 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring; 1050 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1054 struct pci_dev *pdev = adapter->pdev; 1051 struct pci_dev *pdev = adapter->pdev;
1055 uint32_t rctl; 1052 uint32_t rctl;
1056 int size, i, ret_val; 1053 int i, ret_val;
1057 1054
1058 /* Setup Tx descriptor ring and Tx buffers */ 1055 /* Setup Tx descriptor ring and Tx buffers */
1059 1056
1060 if (!txdr->count) 1057 if (!txdr->count)
1061 txdr->count = E1000_DEFAULT_TXD; 1058 txdr->count = E1000_DEFAULT_TXD;
1062 1059
1063 size = txdr->count * sizeof(struct e1000_buffer); 1060 if (!(txdr->buffer_info = kcalloc(txdr->count,
1064 if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) { 1061 sizeof(struct e1000_buffer),
1062 GFP_KERNEL))) {
1065 ret_val = 1; 1063 ret_val = 1;
1066 goto err_nomem; 1064 goto err_nomem;
1067 } 1065 }
1068 memset(txdr->buffer_info, 0, size);
1069 1066
1070 txdr->size = txdr->count * sizeof(struct e1000_tx_desc); 1067 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1071 E1000_ROUNDUP(txdr->size, 4096); 1068 E1000_ROUNDUP(txdr->size, 4096);
1072 if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma))) { 1069 if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size,
1070 &txdr->dma))) {
1073 ret_val = 2; 1071 ret_val = 2;
1074 goto err_nomem; 1072 goto err_nomem;
1075 } 1073 }
@@ -1116,12 +1114,12 @@ e1000_setup_desc_rings(struct e1000_adapter *adapter)
1116 if (!rxdr->count) 1114 if (!rxdr->count)
1117 rxdr->count = E1000_DEFAULT_RXD; 1115 rxdr->count = E1000_DEFAULT_RXD;
1118 1116
1119 size = rxdr->count * sizeof(struct e1000_buffer); 1117 if (!(rxdr->buffer_info = kcalloc(rxdr->count,
1120 if (!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) { 1118 sizeof(struct e1000_buffer),
1119 GFP_KERNEL))) {
1121 ret_val = 4; 1120 ret_val = 4;
1122 goto err_nomem; 1121 goto err_nomem;
1123 } 1122 }
1124 memset(rxdr->buffer_info, 0, size);
1125 1123
1126 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc); 1124 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
1127 if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) { 1125 if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index ed638d676fcf..7b124840bbcc 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -1354,31 +1354,27 @@ e1000_sw_init(struct e1000_adapter *adapter)
1354static int __devinit 1354static int __devinit
1355e1000_alloc_queues(struct e1000_adapter *adapter) 1355e1000_alloc_queues(struct e1000_adapter *adapter)
1356{ 1356{
1357 int size; 1357 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1358 1358 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1359 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1360 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1361 if (!adapter->tx_ring) 1359 if (!adapter->tx_ring)
1362 return -ENOMEM; 1360 return -ENOMEM;
1363 memset(adapter->tx_ring, 0, size);
1364 1361
1365 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues; 1362 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1366 adapter->rx_ring = kmalloc(size, GFP_KERNEL); 1363 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1367 if (!adapter->rx_ring) { 1364 if (!adapter->rx_ring) {
1368 kfree(adapter->tx_ring); 1365 kfree(adapter->tx_ring);
1369 return -ENOMEM; 1366 return -ENOMEM;
1370 } 1367 }
1371 memset(adapter->rx_ring, 0, size);
1372 1368
1373#ifdef CONFIG_E1000_NAPI 1369#ifdef CONFIG_E1000_NAPI
1374 size = sizeof(struct net_device) * adapter->num_rx_queues; 1370 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1375 adapter->polling_netdev = kmalloc(size, GFP_KERNEL); 1371 sizeof(struct net_device),
1372 GFP_KERNEL);
1376 if (!adapter->polling_netdev) { 1373 if (!adapter->polling_netdev) {
1377 kfree(adapter->tx_ring); 1374 kfree(adapter->tx_ring);
1378 kfree(adapter->rx_ring); 1375 kfree(adapter->rx_ring);
1379 return -ENOMEM; 1376 return -ENOMEM;
1380 } 1377 }
1381 memset(adapter->polling_netdev, 0, size);
1382#endif 1378#endif
1383 1379
1384 return E1000_SUCCESS; 1380 return E1000_SUCCESS;
@@ -1774,18 +1770,18 @@ e1000_setup_rx_resources(struct e1000_adapter *adapter,
1774 } 1770 }
1775 memset(rxdr->buffer_info, 0, size); 1771 memset(rxdr->buffer_info, 0, size);
1776 1772
1777 size = sizeof(struct e1000_ps_page) * rxdr->count; 1773 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1778 rxdr->ps_page = kmalloc(size, GFP_KERNEL); 1774 GFP_KERNEL);
1779 if (!rxdr->ps_page) { 1775 if (!rxdr->ps_page) {
1780 vfree(rxdr->buffer_info); 1776 vfree(rxdr->buffer_info);
1781 DPRINTK(PROBE, ERR, 1777 DPRINTK(PROBE, ERR,
1782 "Unable to allocate memory for the receive descriptor ring\n"); 1778 "Unable to allocate memory for the receive descriptor ring\n");
1783 return -ENOMEM; 1779 return -ENOMEM;
1784 } 1780 }
1785 memset(rxdr->ps_page, 0, size);
1786 1781
1787 size = sizeof(struct e1000_ps_page_dma) * rxdr->count; 1782 rxdr->ps_page_dma = kcalloc(rxdr->count,
1788 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL); 1783 sizeof(struct e1000_ps_page_dma),
1784 GFP_KERNEL);
1789 if (!rxdr->ps_page_dma) { 1785 if (!rxdr->ps_page_dma) {
1790 vfree(rxdr->buffer_info); 1786 vfree(rxdr->buffer_info);
1791 kfree(rxdr->ps_page); 1787 kfree(rxdr->ps_page);
@@ -1793,7 +1789,6 @@ e1000_setup_rx_resources(struct e1000_adapter *adapter,
1793 "Unable to allocate memory for the receive descriptor ring\n"); 1789 "Unable to allocate memory for the receive descriptor ring\n");
1794 return -ENOMEM; 1790 return -ENOMEM;
1795 } 1791 }
1796 memset(rxdr->ps_page_dma, 0, size);
1797 1792
1798 if (adapter->hw.mac_type <= e1000_82547_rev_2) 1793 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1799 desc_len = sizeof(struct e1000_rx_desc); 1794 desc_len = sizeof(struct e1000_rx_desc);