From e1e1c08a53faecd6504a063b08dc5616135a773d Mon Sep 17 00:00:00 2001 From: Nithin Dabilpuram Date: Thu, 17 Jan 2019 14:13:54 +0000 Subject: [PATCH] ethdev: report error on ring name truncation Currently this api doesn't report error if name is truncated and so user is not sure about uniqueness of name. This change reports error to help user. Signed-off-by: Nithin Dabilpuram Acked-by: Thomas Monjalon --- lib/librte_ethdev/rte_ethdev.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 9d5107dce3..0d192a24b2 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -3588,9 +3588,15 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name, { char z_name[RTE_MEMZONE_NAMESIZE]; const struct rte_memzone *mz; + int rc; - snprintf(z_name, sizeof(z_name), "eth_p%d_q%d_%s", - dev->data->port_id, queue_id, ring_name); + rc = snprintf(z_name, sizeof(z_name), "eth_p%d_q%d_%s", + dev->data->port_id, queue_id, ring_name); + if (rc >= RTE_MEMZONE_NAMESIZE) { + RTE_ETHDEV_LOG(ERR, "ring name too long\n"); + rte_errno = ENAMETOOLONG; + return NULL; + } mz = rte_memzone_lookup(z_name); if (mz) -- 2.20.1