ethdev: forbid closing started device
authorAndrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Wed, 20 Oct 2021 13:15:40 +0000 (16:15 +0300)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 20 Oct 2021 17:24:22 +0000 (19:24 +0200)
Ethernet device must be stopped first before close in accordance
with the documentation.

Fixes: 980995f8cc56 ("ethdev: improve API comments of close and detach functions")
Cc: stable@dpdk.org
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
lib/ethdev/rte_ethdev.c

index 3b8ef9e..f981e02 100644 (file)
@@ -1893,6 +1893,12 @@ rte_eth_dev_close(uint16_t port_id)
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
+       if (dev->data->dev_started) {
+               RTE_ETHDEV_LOG(ERR, "Cannot close started device (port %u)\n",
+                              port_id);
+               return -EINVAL;
+       }
+
        RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
        *lasterr = (*dev->dev_ops->dev_close)(dev);
        if (*lasterr != 0)