ethdev: prevent from starting/stopping already started/stopped device
authorKonstantin Ananyev <konstantin.ananyev@intel.com>
Mon, 9 Jun 2014 17:26:16 +0000 (18:26 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 10 Jun 2014 22:29:36 +0000 (00:29 +0200)
Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
lib/librte_ether/rte_ethdev.c

index d10982f..ab7137c 100644 (file)
@@ -764,6 +764,14 @@ rte_eth_dev_start(uint8_t port_id)
        dev = &rte_eth_devices[port_id];
 
        FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
+
+       if (dev->data->dev_started != 0) {
+               PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
+                       " already started\n",
+                       port_id);
+               return (0);
+       }
+
        diag = (*dev->dev_ops->dev_start)(dev);
        if (diag == 0)
                dev->data->dev_started = 1;
@@ -791,6 +799,14 @@ rte_eth_dev_stop(uint8_t port_id)
        dev = &rte_eth_devices[port_id];
 
        FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
+
+       if (dev->data->dev_started == 0) {
+               PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
+                       " already stopped\n",
+                       port_id);
+               return;
+       }
+
        dev->data->dev_started = 0;
        (*dev->dev_ops->dev_stop)(dev);
 }