[v3] ethdev: report error on name truncation

Message ID 20190117141316.24187-1-ndabilpuram@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v3] ethdev: report error on name truncation |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Nithin Dabilpuram Jan. 17, 2019, 2:13 p.m. UTC
  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 <ndabilpuram@marvell.com>
---
v3:
Change log message
v2:
Fix issue caused by rebase and also fix log message

 lib/librte_ethdev/rte_ethdev.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
  

Comments

Thomas Monjalon Jan. 17, 2019, 3:38 p.m. UTC | #1
17/01/2019 15:13, Nithin Kumar Dabilpuram:
> 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 <ndabilpuram@marvell.com>
> ---
> +	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;
> +	}

Usually we don't insert a blank line before a test of a return value.
It's really a nitpick, so Ferruh, it's up to you to keep it or not when applying.

Acked-by: Thomas Monjalon <thomas@monjalon.net>
  
Ferruh Yigit Jan. 17, 2019, 5:07 p.m. UTC | #2
On 1/17/2019 3:38 PM, Thomas Monjalon wrote:
> 17/01/2019 15:13, Nithin Kumar Dabilpuram:
>> 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 <ndabilpuram@marvell.com>
>> ---
>> +	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;
>> +	}
> 
> Usually we don't insert a blank line before a test of a return value.
> It's really a nitpick, so Ferruh, it's up to you to keep it or not when applying.
> 
> Acked-by: Thomas Monjalon <thomas@monjalon.net>
> 

Applied to dpdk-next-net/master, thanks.

(Blank line removed while merging)
  

Patch

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 9d5107d..474f305 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -3588,9 +3588,16 @@  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)