diff mbox

linux-generic: tm: handle pktout queue check properly

Message ID 1470580352-11514-1-git-send-email-bill.fischofer@linaro.org
State Superseded
Headers show

Commit Message

Bill Fischofer Aug. 7, 2016, 2:32 p.m. UTC
Resolve bug https://bugs.linaro.org/show_bug.cgi?id=2458 by only checking
for a proper pktout_queue count if the egress_kind is ODP_TM_EGRESS_PKT_IO.

This check is also moved before locking and allocating a tm_system struct
to avoid deadlocks and memory leaks that were another side-effect of this
bug.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
 platform/linux-generic/odp_traffic_mngr.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

-- 
2.7.4
diff mbox

Patch

diff --git a/platform/linux-generic/odp_traffic_mngr.c b/platform/linux-generic/odp_traffic_mngr.c
index e668bf9..07db534 100644
--- a/platform/linux-generic/odp_traffic_mngr.c
+++ b/platform/linux-generic/odp_traffic_mngr.c
@@ -2613,6 +2613,13 @@  odp_tm_t odp_tm_create(const char            *name,
 	uint32_t max_tm_queues, max_sorted_lists;
 	int rc;
 
+	/* If we are using pktio output (usual case) get the first associated
+	 * pktout_queue for this pktio and fail if there isn't one.
+	 */
+	if (egress->egress_kind == ODP_TM_EGRESS_PKT_IO &&
+	    odp_pktout_queue(egress->pktio, &pktout, 1) != 1)
+		return ODP_TM_INVALID;
+
 	/* Allocate tm_system_t record. */
 	odp_ticketlock_lock(&tm_create_lock);
 	tm_system = tm_system_alloc();
@@ -2629,9 +2636,6 @@  odp_tm_t odp_tm_create(const char            *name,
 		return ODP_TM_INVALID;
 	}
 
-	if (odp_pktout_queue(egress->pktio, &pktout, 1) != 1)
-		return ODP_TM_INVALID;
-
 	tm_system->pktout = pktout;
 	tm_system->name_tbl_id = name_tbl_id;
 	max_tm_queues = requirements->max_tm_queues;