mbuf: check shared memory before dumping dynamic space

Because mbuf dyn shared memory was allocated runtime, so it's
necessary to check validity when dump mbuf dyn info.

Also this patch adds an error logging when init shared memory fail.

Fixes: 4958ca3a44 ("mbuf: support dynamic fields and flags")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
This commit is contained in:
Chengwen Feng 2021-04-23 16:11:04 +08:00 committed by Thomas Monjalon
parent 2231388f21
commit d4902ed31c

View File

@ -115,8 +115,10 @@ init_shared_mem(void)
} else { } else {
mz = rte_memzone_lookup(RTE_MBUF_DYN_MZNAME); mz = rte_memzone_lookup(RTE_MBUF_DYN_MZNAME);
} }
if (mz == NULL) if (mz == NULL) {
RTE_LOG(ERR, MBUF, "Failed to get mbuf dyn shared memory\n");
return -1; return -1;
}
shm = mz->addr; shm = mz->addr;
@ -525,7 +527,11 @@ void rte_mbuf_dyn_dump(FILE *out)
size_t i; size_t i;
rte_mcfg_tailq_write_lock(); rte_mcfg_tailq_write_lock();
init_shared_mem(); if (init_shared_mem() < 0) {
rte_mcfg_tailq_write_unlock();
return;
}
fprintf(out, "Reserved fields:\n"); fprintf(out, "Reserved fields:\n");
mbuf_dynfield_list = RTE_TAILQ_CAST( mbuf_dynfield_list = RTE_TAILQ_CAST(
mbuf_dynfield_tailq.head, mbuf_dynfield_list); mbuf_dynfield_tailq.head, mbuf_dynfield_list);