[09/31] common/cnxk: fix leak in error path

Message ID 20230811085805.441256-9-ndabilpuram@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers
Series [01/31] common/cnxk: add aura ref count mechanism |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Nithin Dabilpuram Aug. 11, 2023, 8:57 a.m. UTC
  From: Akhil Goyal <gakhil@marvell.com>

Fixed resource leak when pthread create fails in dev_init().

Fixes: 1c7a4d37e73d ("common/cnxk: fix mailbox timeout due to deadlock")

Signed-off-by: Akhil Goyal <gakhil@marvell.com>
---
 drivers/common/cnxk/roc_dev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Patch

diff --git a/drivers/common/cnxk/roc_dev.c b/drivers/common/cnxk/roc_dev.c
index 128b9751e4..18d7981825 100644
--- a/drivers/common/cnxk/roc_dev.c
+++ b/drivers/common/cnxk/roc_dev.c
@@ -1472,7 +1472,7 @@  dev_init(struct dev *dev, struct plt_pci_device *pci_dev)
 					    pf_vf_mbox_thread_main, dev);
 		if (rc != 0) {
 			plt_err("Failed to create thread for VF mbox handling\n");
-			goto iounmap;
+			goto thread_fail;
 		}
 	}
 
@@ -1500,9 +1500,10 @@  dev_init(struct dev *dev, struct plt_pci_device *pci_dev)
 		dev->sync.start_thread = false;
 		pthread_cond_signal(&dev->sync.pfvf_msg_cond);
 		pthread_join(dev->sync.pfvf_msg_thread, NULL);
-		pthread_mutex_destroy(&dev->sync.mutex);
-		pthread_cond_destroy(&dev->sync.pfvf_msg_cond);
 	}
+thread_fail:
+	pthread_mutex_destroy(&dev->sync.mutex);
+	pthread_cond_destroy(&dev->sync.pfvf_msg_cond);
 iounmap:
 	dev_vf_mbase_put(pci_dev, vf_mbase);
 mbox_unregister: