diff options
author | Alexander Duyck <alexander.h.duyck@intel.com> | 2009-10-27 19:49:20 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-10-28 06:25:48 -0400 |
commit | 439705e1d7281cc8a4631a2dc390df7ad868bad8 (patch) | |
tree | 5c817cb6065a8172b10c70a92c0306933e87dcab /drivers/net/igb | |
parent | f7ba205e823f32e634712323a221b42bfea06efa (diff) |
igb: cleanup code related to ring resource allocation and free
This patch cleans up some of the ring alloc and free code to better handle
exceptions such as attempting to free resources on an already freed ring.
Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/igb')
-rw-r--r-- | drivers/net/igb/igb_main.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c index f75f90ff8138..e67ff0ea2a56 100644 --- a/drivers/net/igb/igb_main.c +++ b/drivers/net/igb/igb_main.c | |||
@@ -1952,7 +1952,8 @@ int igb_setup_tx_resources(struct igb_ring *tx_ring) | |||
1952 | tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc); | 1952 | tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc); |
1953 | tx_ring->size = ALIGN(tx_ring->size, 4096); | 1953 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
1954 | 1954 | ||
1955 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, | 1955 | tx_ring->desc = pci_alloc_consistent(pdev, |
1956 | tx_ring->size, | ||
1956 | &tx_ring->dma); | 1957 | &tx_ring->dma); |
1957 | 1958 | ||
1958 | if (!tx_ring->desc) | 1959 | if (!tx_ring->desc) |
@@ -1978,13 +1979,13 @@ err: | |||
1978 | **/ | 1979 | **/ |
1979 | static int igb_setup_all_tx_resources(struct igb_adapter *adapter) | 1980 | static int igb_setup_all_tx_resources(struct igb_adapter *adapter) |
1980 | { | 1981 | { |
1982 | struct pci_dev *pdev = adapter->pdev; | ||
1981 | int i, err = 0; | 1983 | int i, err = 0; |
1982 | int r_idx; | ||
1983 | 1984 | ||
1984 | for (i = 0; i < adapter->num_tx_queues; i++) { | 1985 | for (i = 0; i < adapter->num_tx_queues; i++) { |
1985 | err = igb_setup_tx_resources(&adapter->tx_ring[i]); | 1986 | err = igb_setup_tx_resources(&adapter->tx_ring[i]); |
1986 | if (err) { | 1987 | if (err) { |
1987 | dev_err(&adapter->pdev->dev, | 1988 | dev_err(&pdev->dev, |
1988 | "Allocation for Tx Queue %u failed\n", i); | 1989 | "Allocation for Tx Queue %u failed\n", i); |
1989 | for (i--; i >= 0; i--) | 1990 | for (i--; i >= 0; i--) |
1990 | igb_free_tx_resources(&adapter->tx_ring[i]); | 1991 | igb_free_tx_resources(&adapter->tx_ring[i]); |
@@ -1993,7 +1994,7 @@ static int igb_setup_all_tx_resources(struct igb_adapter *adapter) | |||
1993 | } | 1994 | } |
1994 | 1995 | ||
1995 | for (i = 0; i < IGB_MAX_TX_QUEUES; i++) { | 1996 | for (i = 0; i < IGB_MAX_TX_QUEUES; i++) { |
1996 | r_idx = i % adapter->num_tx_queues; | 1997 | int r_idx = i % adapter->num_tx_queues; |
1997 | adapter->multi_tx_table[i] = &adapter->tx_ring[r_idx]; | 1998 | adapter->multi_tx_table[i] = &adapter->tx_ring[r_idx]; |
1998 | } | 1999 | } |
1999 | return err; | 2000 | return err; |
@@ -2116,6 +2117,7 @@ int igb_setup_rx_resources(struct igb_ring *rx_ring) | |||
2116 | 2117 | ||
2117 | err: | 2118 | err: |
2118 | vfree(rx_ring->buffer_info); | 2119 | vfree(rx_ring->buffer_info); |
2120 | rx_ring->buffer_info = NULL; | ||
2119 | dev_err(&pdev->dev, "Unable to allocate memory for " | 2121 | dev_err(&pdev->dev, "Unable to allocate memory for " |
2120 | "the receive descriptor ring\n"); | 2122 | "the receive descriptor ring\n"); |
2121 | return -ENOMEM; | 2123 | return -ENOMEM; |
@@ -2130,12 +2132,13 @@ err: | |||
2130 | **/ | 2132 | **/ |
2131 | static int igb_setup_all_rx_resources(struct igb_adapter *adapter) | 2133 | static int igb_setup_all_rx_resources(struct igb_adapter *adapter) |
2132 | { | 2134 | { |
2135 | struct pci_dev *pdev = adapter->pdev; | ||
2133 | int i, err = 0; | 2136 | int i, err = 0; |
2134 | 2137 | ||
2135 | for (i = 0; i < adapter->num_rx_queues; i++) { | 2138 | for (i = 0; i < adapter->num_rx_queues; i++) { |
2136 | err = igb_setup_rx_resources(&adapter->rx_ring[i]); | 2139 | err = igb_setup_rx_resources(&adapter->rx_ring[i]); |
2137 | if (err) { | 2140 | if (err) { |
2138 | dev_err(&adapter->pdev->dev, | 2141 | dev_err(&pdev->dev, |
2139 | "Allocation for Rx Queue %u failed\n", i); | 2142 | "Allocation for Rx Queue %u failed\n", i); |
2140 | for (i--; i >= 0; i--) | 2143 | for (i--; i >= 0; i--) |
2141 | igb_free_rx_resources(&adapter->rx_ring[i]); | 2144 | igb_free_rx_resources(&adapter->rx_ring[i]); |
@@ -2476,6 +2479,10 @@ void igb_free_tx_resources(struct igb_ring *tx_ring) | |||
2476 | vfree(tx_ring->buffer_info); | 2479 | vfree(tx_ring->buffer_info); |
2477 | tx_ring->buffer_info = NULL; | 2480 | tx_ring->buffer_info = NULL; |
2478 | 2481 | ||
2482 | /* if not set, then don't free */ | ||
2483 | if (!tx_ring->desc) | ||
2484 | return; | ||
2485 | |||
2479 | pci_free_consistent(tx_ring->pdev, tx_ring->size, | 2486 | pci_free_consistent(tx_ring->pdev, tx_ring->size, |
2480 | tx_ring->desc, tx_ring->dma); | 2487 | tx_ring->desc, tx_ring->dma); |
2481 | 2488 | ||
@@ -2534,14 +2541,10 @@ static void igb_clean_tx_ring(struct igb_ring *tx_ring) | |||
2534 | memset(tx_ring->buffer_info, 0, size); | 2541 | memset(tx_ring->buffer_info, 0, size); |
2535 | 2542 | ||
2536 | /* Zero out the descriptor ring */ | 2543 | /* Zero out the descriptor ring */ |
2537 | |||
2538 | memset(tx_ring->desc, 0, tx_ring->size); | 2544 | memset(tx_ring->desc, 0, tx_ring->size); |
2539 | 2545 | ||
2540 | tx_ring->next_to_use = 0; | 2546 | tx_ring->next_to_use = 0; |
2541 | tx_ring->next_to_clean = 0; | 2547 | tx_ring->next_to_clean = 0; |
2542 | |||
2543 | writel(0, tx_ring->head); | ||
2544 | writel(0, tx_ring->tail); | ||
2545 | } | 2548 | } |
2546 | 2549 | ||
2547 | /** | 2550 | /** |
@@ -2569,6 +2572,10 @@ void igb_free_rx_resources(struct igb_ring *rx_ring) | |||
2569 | vfree(rx_ring->buffer_info); | 2572 | vfree(rx_ring->buffer_info); |
2570 | rx_ring->buffer_info = NULL; | 2573 | rx_ring->buffer_info = NULL; |
2571 | 2574 | ||
2575 | /* if not set, then don't free */ | ||
2576 | if (!rx_ring->desc) | ||
2577 | return; | ||
2578 | |||
2572 | pci_free_consistent(rx_ring->pdev, rx_ring->size, | 2579 | pci_free_consistent(rx_ring->pdev, rx_ring->size, |
2573 | rx_ring->desc, rx_ring->dma); | 2580 | rx_ring->desc, rx_ring->dma); |
2574 | 2581 | ||
@@ -2601,6 +2608,7 @@ static void igb_clean_rx_ring(struct igb_ring *rx_ring) | |||
2601 | 2608 | ||
2602 | if (!rx_ring->buffer_info) | 2609 | if (!rx_ring->buffer_info) |
2603 | return; | 2610 | return; |
2611 | |||
2604 | /* Free all the Rx ring sk_buffs */ | 2612 | /* Free all the Rx ring sk_buffs */ |
2605 | for (i = 0; i < rx_ring->count; i++) { | 2613 | for (i = 0; i < rx_ring->count; i++) { |
2606 | buffer_info = &rx_ring->buffer_info[i]; | 2614 | buffer_info = &rx_ring->buffer_info[i]; |
@@ -2638,9 +2646,6 @@ static void igb_clean_rx_ring(struct igb_ring *rx_ring) | |||
2638 | 2646 | ||
2639 | rx_ring->next_to_clean = 0; | 2647 | rx_ring->next_to_clean = 0; |
2640 | rx_ring->next_to_use = 0; | 2648 | rx_ring->next_to_use = 0; |
2641 | |||
2642 | writel(0, rx_ring->head); | ||
2643 | writel(0, rx_ring->tail); | ||
2644 | } | 2649 | } |
2645 | 2650 | ||
2646 | /** | 2651 | /** |