ixgbe: Add a few safety nets for register writes and descriptor cleanups
authorJesse Brandeburg <jesse.brandeburg@intel.com>
Fri, 13 Mar 2009 22:14:50 +0000 (22:14 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 14 Mar 2009 19:41:12 +0000 (12:41 -0700)
There are possible times that a driver may fail to completely initialize,
due to a buggy platform or a buggy kernel.  In those cases, we'd rather
fail gracefully instead of a panic.  Add a few safety checks to some
critical paths to try and prevent a panic in these corner-case situations.

Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ixgbe/ixgbe_main.c

index 39781c84dafc8e5721364a6cfe7d7ec569d1dd96..892195f2ad9b75691328d1de95f0b053ebcef06e 100644 (file)
@@ -2458,8 +2458,10 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
        rx_ring->next_to_clean = 0;
        rx_ring->next_to_use = 0;
 
-       writel(0, adapter->hw.hw_addr + rx_ring->head);
-       writel(0, adapter->hw.hw_addr + rx_ring->tail);
+       if (rx_ring->head)
+               writel(0, adapter->hw.hw_addr + rx_ring->head);
+       if (rx_ring->tail)
+               writel(0, adapter->hw.hw_addr + rx_ring->tail);
 }
 
 /**
@@ -2490,8 +2492,10 @@ static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
        tx_ring->next_to_use = 0;
        tx_ring->next_to_clean = 0;
 
-       writel(0, adapter->hw.hw_addr + tx_ring->head);
-       writel(0, adapter->hw.hw_addr + tx_ring->tail);
+       if (tx_ring->head)
+               writel(0, adapter->hw.hw_addr + tx_ring->head);
+       if (tx_ring->tail)
+               writel(0, adapter->hw.hw_addr + tx_ring->tail);
 }
 
 /**
@@ -3327,7 +3331,8 @@ static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
        int i;
 
        for (i = 0; i < adapter->num_tx_queues; i++)
-               ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
+               if (adapter->tx_ring[i].desc)
+                       ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
 }
 
 /**
@@ -3363,7 +3368,8 @@ static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
        int i;
 
        for (i = 0; i < adapter->num_rx_queues; i++)
-               ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
+               if (adapter->rx_ring[i].desc)
+                       ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
 }
 
 /**