net/sfc: carefully cleanup on init failure and shutdown
authorAndrew Rybchenko <arybchenko@solarflare.com>
Thu, 18 May 2017 14:00:02 +0000 (15:00 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 12 Jun 2017 09:41:26 +0000 (10:41 +0100)
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@solarflare.com>
drivers/net/sfc/sfc_ethdev.c

index 223da1c..c4d74d0 100644 (file)
@@ -1407,7 +1407,7 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                                "Insufficient Hw/FW capabilities to use Rx datapath %s",
                                rx_name);
                        rc = EINVAL;
-                       goto fail_dp_rx;
+                       goto fail_dp_rx_caps;
                }
        } else {
                sa->dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps);
@@ -1440,7 +1440,7 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                                "Insufficient Hw/FW capabilities to use Tx datapath %s",
                                tx_name);
                        rc = EINVAL;
-                       goto fail_dp_tx;
+                       goto fail_dp_tx_caps;
                }
        } else {
                sa->dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps);
@@ -1460,13 +1460,32 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
 
        return 0;
 
+fail_dp_tx_caps:
+       sa->dp_tx = NULL;
+
 fail_dp_tx:
 fail_kvarg_tx_datapath:
+fail_dp_rx_caps:
+       sa->dp_rx = NULL;
+
 fail_dp_rx:
 fail_kvarg_rx_datapath:
        return rc;
 }
 
+static void
+sfc_eth_dev_clear_ops(struct rte_eth_dev *dev)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+
+       dev->dev_ops = NULL;
+       dev->rx_pkt_burst = NULL;
+       dev->tx_pkt_burst = NULL;
+
+       sa->dp_tx = NULL;
+       sa->dp_rx = NULL;
+}
+
 static void
 sfc_register_dp(void)
 {
@@ -1549,6 +1568,8 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
        return 0;
 
 fail_attach:
+       sfc_eth_dev_clear_ops(dev);
+
 fail_set_ops:
        sfc_unprobe(sa);
 
@@ -1577,16 +1598,14 @@ sfc_eth_dev_uninit(struct rte_eth_dev *dev)
 
        sfc_adapter_lock(sa);
 
+       sfc_eth_dev_clear_ops(dev);
+
        sfc_detach(sa);
        sfc_unprobe(sa);
 
        rte_free(dev->data->mac_addrs);
        dev->data->mac_addrs = NULL;
 
-       dev->dev_ops = NULL;
-       dev->rx_pkt_burst = NULL;
-       dev->tx_pkt_burst = NULL;
-
        sfc_kvargs_cleanup(sa);
 
        sfc_adapter_unlock(sa);