From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id A60C51B4B9; Thu, 2 Aug 2018 16:43:35 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Aug 2018 07:43:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,436,1526367600"; d="scan'208";a="72779704" Received: from silpixa00399779.ir.intel.com ([10.237.223.187]) by fmsmga002.fm.intel.com with ESMTP; 02 Aug 2018 07:43:32 -0700 From: Harry van Haaren To: dev@dpdk.org Cc: Harry van Haaren , bruce.richardson@intel.com, stable@dpdk.org, thomas@monjalon.net, jerin.jacob@caviumnetworks.com Date: Thu, 2 Aug 2018 15:43:29 +0100 Message-Id: <1533221009-99302-1-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533198964-30218-1-git-send-email-harry.van.haaren@intel.com> References: <1533198964-30218-1-git-send-email-harry.van.haaren@intel.com> Subject: [dpdk-dev] [PATCH v2] event: fix check in ring init() in event ring code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2018 14:43:36 -0000 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: bruce.richardson@intel.com Cc: stable@dpdk.org Signed-off-by: Harry van Haaren Acked-by: Jerin Jacob --- v2: - Removed _ from headline for check git log (Jerin) - Added memzone free (good catch, thanks Jerin) - Return NULL instead of 0 (Jerin) - Added Jerin's Ack Cc: thomas@monjalon.net Cc: jerin.jacob@caviumnetworks.com Please consider this for RC3, as it fixes the unit tests on 32-bit systems. --- lib/librte_eventdev/rte_event_ring.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/librte_eventdev/rte_event_ring.c b/lib/librte_eventdev/rte_event_ring.c index eb67751..16d02a9 100644 --- a/lib/librte_eventdev/rte_event_ring.c +++ b/lib/librte_eventdev/rte_event_ring.c @@ -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; -- 2.7.4