event: fix ring init failure handling
authorHarry van Haaren <harry.van.haaren@intel.com>
Thu, 2 Aug 2018 14:43:29 +0000 (15:43 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Sun, 5 Aug 2018 12:52:19 +0000 (14:52 +0200)
This commit fixes a bug in a 32-bit environment where the
generic ring_init() would fail, but given the interaction
with memzones the next iteration of the event_ring_autotest
would actually *pass* because the ring in question would
exist already an be looked-up.

This commit rightly error checks the result of ring_init(),
and calls rte_free() on the memory as required.

Fixes: dc39e2f359b5 ("eventdev: add ring structure for events")
Cc: stable@dpdk.org
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
lib/librte_eventdev/rte_event_ring.c

index eb67751..16d02a9 100644 (file)
@@ -82,11 +82,16 @@ rte_event_ring_create(const char *name, unsigned int count, int socket_id,
        mz = rte_memzone_reserve(mz_name, ring_size, socket_id, mz_flags);
        if (mz != NULL) {
                r = mz->addr;
-               /*
-                * no need to check return value here, we already checked the
-                * arguments above
-                */
-               rte_event_ring_init(r, name, requested_count, flags);
+               /* Check return value in case rte_ring_init() fails on size */
+               int err = rte_event_ring_init(r, name, requested_count, flags);
+               if (err) {
+                       RTE_LOG(ERR, RING, "Ring init failed\n");
+                       if (rte_memzone_free(mz) != 0)
+                               RTE_LOG(ERR, RING, "Cannot free memzone\n");
+                       rte_free(te);
+                       rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+                       return NULL;
+               }
 
                te->data = (void *) r;
                r->r.memzone = mz;