[dpdk-dev] mbuf:using sanity checks do not panic on null mbuf

Message ID 20180108153423.57648-1-keith.wiles@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Wiles, Keith Jan. 8, 2018, 3:34 p.m. UTC
  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 <keith.wiles@intel.com>
---
 lib/librte_mbuf/rte_mbuf.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Comments

Stephen Hemminger Jan. 8, 2018, 3:39 p.m. UTC | #1
On Mon,  8 Jan 2018 09:34:23 -0600
Keith Wiles <keith.wiles@intel.com> wrote:

> +	if (!m || !f) {
> +		fprintf(stderr, "MBUF and/or FILE pointer is NULL\n");
> +		return;
> +	}

Calling with f of NULL is user error, let it still die in fprintf.
  
Wiles, Keith Jan. 8, 2018, 3:41 p.m. UTC | #2
> On Jan 8, 2018, at 9:39 AM, Stephen Hemminger <stephen@networkplumber.org> wrote:
> 
> On Mon,  8 Jan 2018 09:34:23 -0600
> Keith Wiles <keith.wiles@intel.com> wrote:
> 
>> +	if (!m || !f) {
>> +		fprintf(stderr, "MBUF and/or FILE pointer is NULL\n");
>> +		return;
>> +	}
> 
> Calling with f of NULL is user error, let it still die in fprintf.

I thought about that too, but this routine is a debug routine does it really matter?

Regards,
Keith
  
Jerin Jacob Jan. 9, 2018, 4:39 a.m. UTC | #3
-----Original Message-----
> Date: Mon, 8 Jan 2018 09:34:23 -0600
> From: Keith Wiles <keith.wiles@intel.com>
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null
>  mbuf
> X-Mailer: git-send-email 2.10.1
> 
> 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 <keith.wiles@intel.com>

mbuf autotest is failing with this change.

# echo "mbuf_autotest" | sudo ./build/app/test

<snip>

Checking rte_mbuf_sanity_check for failure conditions
Checking good mbuf initially
Now checking for error conditions
Error with NULL mbuf test
test_failing_mbuf_sanity_check() failed
Test Failed
  

Patch

diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
index 7543662f7..58184c4f4 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 || !f) {
+		fprintf(stderr, "MBUF and/or FILE 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, "