From b507905ff407f53ac87ec6c4a10a5f7000ecb062 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Wed, 22 Apr 2015 11:57:21 +0200 Subject: [PATCH] mbuf: fix init when private size is not zero Allow the user to use the default rte_pktmbuf_init() function even if the mbuf private size is not 0. Signed-off-by: Olivier Matz Acked-by: Neil Horman Acked-by: Konstantin Ananyev --- lib/librte_mbuf/rte_mbuf.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 231cfb8d25..d1f2a6f565 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -119,16 +119,19 @@ rte_pktmbuf_init(struct rte_mempool *mp, __attribute__((unused)) unsigned i) { struct rte_mbuf *m = _m; - uint32_t buf_len = mp->elt_size - sizeof(struct rte_mbuf); + uint32_t mbuf_size, buf_len; - RTE_MBUF_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf)); + mbuf_size = sizeof(struct rte_mbuf) + rte_pktmbuf_priv_size(mp); + buf_len = rte_pktmbuf_data_room_size(mp); + + RTE_MBUF_ASSERT(mp->elt_size >= mbuf_size); + RTE_MBUF_ASSERT(buf_len <= UINT16_MAX); memset(m, 0, mp->elt_size); /* start of buffer is just after mbuf structure */ - m->buf_addr = (char *)m + sizeof(struct rte_mbuf); - m->buf_physaddr = rte_mempool_virt2phy(mp, m) + - sizeof(struct rte_mbuf); + m->buf_addr = (char *)m + mbuf_size; + m->buf_physaddr = rte_mempool_virt2phy(mp, m) + mbuf_size; m->buf_len = (uint16_t)buf_len; /* keep some headroom between start of buffer and data */ -- 2.20.1