e1000e: prevent oops when adapter is being closed and reset simultaneously
authorBruce Allan <bruce.w.allan@intel.com>
Wed, 21 Mar 2012 00:39:12 +0000 (00:39 +0000)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Tue, 3 Apr 2012 22:25:08 +0000 (15:25 -0700)
When the adapter is closed while it is simultaneously going through a
reset, it can cause a null-pointer dereference when the two different code
paths simultaneously cleanup up the Tx/Rx resources.

Signed-off-by: Bruce Allan <bruce.w.allan@intel.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/e1000e/e1000.h
drivers/net/ethernet/intel/e1000e/netdev.c

index 86cdd47939925b64ebe5f3d1859165d6f1880f30..b83897f76ee34786360261d6148c31bcf9563588 100644 (file)
@@ -161,6 +161,12 @@ struct e1000_info;
 /* Time to wait before putting the device into D3 if there's no link (in ms). */
 #define LINK_TIMEOUT           100
 
+/*
+ * Count for polling __E1000_RESET condition every 10-20msec.
+ * Experimentation has shown the reset can take approximately 210msec.
+ */
+#define E1000_CHECK_RESET_COUNT                25
+
 #define DEFAULT_RDTR                   0
 #define DEFAULT_RADV                   8
 #define BURST_RDTR                     0x20
index 2c38a65ade8753df06caf24639f204e5eb90c2fc..6878601f20c54d29aa2a8384ac7f52547e03f30b 100644 (file)
@@ -3968,6 +3968,10 @@ static int e1000_close(struct net_device *netdev)
 {
        struct e1000_adapter *adapter = netdev_priv(netdev);
        struct pci_dev *pdev = adapter->pdev;
+       int count = E1000_CHECK_RESET_COUNT;
+
+       while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
+               usleep_range(10000, 20000);
 
        WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
 
@@ -5472,6 +5476,11 @@ static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
        netif_device_detach(netdev);
 
        if (netif_running(netdev)) {
+               int count = E1000_CHECK_RESET_COUNT;
+
+               while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
+                       usleep_range(10000, 20000);
+
                WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
                e1000e_down(adapter);
                e1000_free_irq(adapter);