From: Gagandeep Singh <[email protected]>

Add a check to avoid closing a device that is already closed,
preventing a double-close condition during device removal.

Note: this also removes the explicit dpaa_finish() call that was
made at last-device remove time (!dpaa_valid_dev). dpaa_finish() is
registered as RTE_FINI_PRIO(dpaa_finish, 103) and will still run at
process exit, so for the normal run-then-exit path behaviour is
unchanged. For a remove-all-then-re-probe scenario, is_global_init
will remain set until exit; re-probe in a running process is not a
supported use case for this driver.

Fixes: 78ea4b4fcb52 ("bus/dpaa: improve cleanup")
Cc: [email protected]

Signed-off-by: Gagandeep Singh <[email protected]>
---
 drivers/net/dpaa/dpaa_ethdev.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c
index 424458857e..9a9c5ee817 100644
--- a/drivers/net/dpaa/dpaa_ethdev.c
+++ b/drivers/net/dpaa/dpaa_ethdev.c
@@ -2674,18 +2674,19 @@ static int
 rte_dpaa_remove(struct rte_dpaa_device *dpaa_dev)
 {
        struct rte_eth_dev *eth_dev;
-       int ret;
+       int ret = 0;
 
        PMD_INIT_FUNC_TRACE();
 
        eth_dev = dpaa_dev->eth_dev;
-       dpaa_eth_dev_close(eth_dev);
-       ret = rte_eth_dev_release_port(eth_dev);
+       if (eth_dev->state !=  RTE_ETH_DEV_UNUSED) {
+               dpaa_eth_dev_close(eth_dev);
+               ret = rte_eth_dev_release_port(eth_dev);
+       }
        dpaa_valid_dev--;
-       if (!dpaa_valid_dev) {
+       if (!dpaa_valid_dev)
                rte_mempool_free(dpaa_tx_sg_pool);
-               dpaa_finish();
-       }
+
        return ret;
 }
 
-- 
2.43.0

Reply via email to