From patchwork Tue Jan 9 14:29:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wiles, Keith" X-Patchwork-Id: 33230 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 08F691B1CC; Tue, 9 Jan 2018 15:29:47 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id C74101B1CA for ; Tue, 9 Jan 2018 15:29:45 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2018 06:29:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,335,1511856000"; d="scan'208";a="9358600" Received: from crodrig4-mobl.amr.corp.intel.com ([10.255.76.120]) by orsmga008.jf.intel.com with ESMTP; 09 Jan 2018 06:29:43 -0800 From: Keith Wiles To: dev@dpdk.org Cc: stephen@networkplumber.org, jerin.jacob@caviumnetworks.com Date: Tue, 9 Jan 2018 08:29:28 -0600 Message-Id: <20180109142928.81687-1-keith.wiles@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20180108153423.57648-1-keith.wiles@intel.com> References: <20180108153423.57648-1-keith.wiles@intel.com> Subject: [dpdk-dev] [PATCH v2] mbuf:using sanity checks do not panic on null mbuf 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The rte_pktmbuf_free() allows for NULL mbuf pointer, but when sanity check is enabled it will panic with null pointer. Signed-off-by: Keith Wiles --- lib/librte_mbuf/rte_mbuf.c | 10 ++++++++-- test/test/test_mbuf.c | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 7543662f7..621679c92 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -205,8 +205,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header) const struct rte_mbuf *m_seg; unsigned int nb_segs; - if (m == NULL) - rte_panic("mbuf is NULL\n"); + /* Calling with NULL is valid in the API */ + if (!m) + return; /* generic checks */ if (m->pool == NULL) @@ -243,6 +244,11 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len) __rte_mbuf_sanity_check(m, 1); + if (!m) { + fprintf(stderr, "MBUF pointer is NULL\n"); + return; + } + fprintf(f, "dump mbuf at %p, iova=%"PRIx64", buf_len=%u\n", m, (uint64_t)m->buf_iova, (unsigned)m->buf_len); fprintf(f, " pkt_len=%"PRIu32", ol_flags=%"PRIx64", nb_segs=%u, " diff --git a/test/test/test_mbuf.c b/test/test/test_mbuf.c index 9e82a20be..146eaf0e5 100644 --- a/test/test/test_mbuf.c +++ b/test/test/test_mbuf.c @@ -864,10 +864,8 @@ test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool) printf("Now checking for error conditions\n"); - if (verify_mbuf_check_panics(NULL)) { - printf("Error with NULL mbuf test\n"); + if (verify_mbuf_check_panics(NULL) != -1) return -1; - } badbuf = *buf; badbuf.pool = NULL;