diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-11-16 22:27:18 -0500 |
---|---|---|
committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2010-11-16 22:27:18 -0500 |
commit | e2ddeba95c09d0d44719ff005e915dc06ff46571 (patch) | |
tree | 840662eeaec906826885de85b7238afd6c8c1345 /drivers | |
parent | b93a22260f6f4bcf6c92c54de8530a97d3e921f0 (diff) |
ixgbe: refactor ixgbe_alloc_queues()
I noticed ring variable was initialized before allocations, and that
memory node management was a bit ugly. We also leak memory in case of
ring allocations error.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/ixgbe/ixgbe_main.c | 72 |
1 files changed, 28 insertions, 44 deletions
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c index b859a298cd2a..5409af3da06c 100644 --- a/drivers/net/ixgbe/ixgbe_main.c +++ b/drivers/net/ixgbe/ixgbe_main.c | |||
@@ -4676,71 +4676,55 @@ static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) | |||
4676 | **/ | 4676 | **/ |
4677 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) | 4677 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
4678 | { | 4678 | { |
4679 | int i; | 4679 | int rx = 0, tx = 0, nid = adapter->node; |
4680 | int rx_count; | ||
4681 | int orig_node = adapter->node; | ||
4682 | 4680 | ||
4683 | for (i = 0; i < adapter->num_tx_queues; i++) { | 4681 | if (nid < 0 || !node_online(nid)) |
4684 | struct ixgbe_ring *ring = adapter->tx_ring[i]; | 4682 | nid = first_online_node; |
4685 | if (orig_node == -1) { | 4683 | |
4686 | int cur_node = next_online_node(adapter->node); | 4684 | for (; tx < adapter->num_tx_queues; tx++) { |
4687 | if (cur_node == MAX_NUMNODES) | 4685 | struct ixgbe_ring *ring; |
4688 | cur_node = first_online_node; | 4686 | |
4689 | adapter->node = cur_node; | 4687 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
4690 | } | ||
4691 | ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL, | ||
4692 | adapter->node); | ||
4693 | if (!ring) | 4688 | if (!ring) |
4694 | ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL); | 4689 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
4695 | if (!ring) | 4690 | if (!ring) |
4696 | goto err_tx_ring_allocation; | 4691 | goto err_allocation; |
4697 | ring->count = adapter->tx_ring_count; | 4692 | ring->count = adapter->tx_ring_count; |
4698 | ring->queue_index = i; | 4693 | ring->queue_index = tx; |
4694 | ring->numa_node = nid; | ||
4699 | ring->dev = &adapter->pdev->dev; | 4695 | ring->dev = &adapter->pdev->dev; |
4700 | ring->netdev = adapter->netdev; | 4696 | ring->netdev = adapter->netdev; |
4701 | ring->numa_node = adapter->node; | ||
4702 | 4697 | ||
4703 | adapter->tx_ring[i] = ring; | 4698 | adapter->tx_ring[tx] = ring; |
4704 | } | 4699 | } |
4705 | 4700 | ||
4706 | /* Restore the adapter's original node */ | 4701 | for (; rx < adapter->num_rx_queues; rx++) { |
4707 | adapter->node = orig_node; | 4702 | struct ixgbe_ring *ring; |
4708 | 4703 | ||
4709 | rx_count = adapter->rx_ring_count; | 4704 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
4710 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
4711 | struct ixgbe_ring *ring = adapter->rx_ring[i]; | ||
4712 | if (orig_node == -1) { | ||
4713 | int cur_node = next_online_node(adapter->node); | ||
4714 | if (cur_node == MAX_NUMNODES) | ||
4715 | cur_node = first_online_node; | ||
4716 | adapter->node = cur_node; | ||
4717 | } | ||
4718 | ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL, | ||
4719 | adapter->node); | ||
4720 | if (!ring) | 4705 | if (!ring) |
4721 | ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL); | 4706 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
4722 | if (!ring) | 4707 | if (!ring) |
4723 | goto err_rx_ring_allocation; | 4708 | goto err_allocation; |
4724 | ring->count = rx_count; | 4709 | ring->count = adapter->rx_ring_count; |
4725 | ring->queue_index = i; | 4710 | ring->queue_index = rx; |
4711 | ring->numa_node = nid; | ||
4726 | ring->dev = &adapter->pdev->dev; | 4712 | ring->dev = &adapter->pdev->dev; |
4727 | ring->netdev = adapter->netdev; | 4713 | ring->netdev = adapter->netdev; |
4728 | ring->numa_node = adapter->node; | ||
4729 | 4714 | ||
4730 | adapter->rx_ring[i] = ring; | 4715 | adapter->rx_ring[rx] = ring; |
4731 | } | 4716 | } |
4732 | 4717 | ||
4733 | /* Restore the adapter's original node */ | ||
4734 | adapter->node = orig_node; | ||
4735 | |||
4736 | ixgbe_cache_ring_register(adapter); | 4718 | ixgbe_cache_ring_register(adapter); |
4737 | 4719 | ||
4738 | return 0; | 4720 | return 0; |
4739 | 4721 | ||
4740 | err_rx_ring_allocation: | 4722 | err_allocation: |
4741 | for (i = 0; i < adapter->num_tx_queues; i++) | 4723 | while (tx) |
4742 | kfree(adapter->tx_ring[i]); | 4724 | kfree(adapter->tx_ring[--tx]); |
4743 | err_tx_ring_allocation: | 4725 | |
4726 | while (rx) | ||
4727 | kfree(adapter->rx_ring[--rx]); | ||
4744 | return -ENOMEM; | 4728 | return -ENOMEM; |
4745 | } | 4729 | } |
4746 | 4730 | ||