ring name length simplification in ipsec_mb_qp_create_processed_ops_ring

Message ID 20230530163457.665dd69a@hermes.local (mailing list archive)
State Changes Requested, archived
Delegated to: akhil goyal
Headers
Series ring name length simplification in ipsec_mb_qp_create_processed_ops_ring |

Checks

Context Check Description
ci/loongarch-compilation warning apply patch failure
ci/Intel-compilation warning apply issues
ci/iol-testing warning apply patch failure

Commit Message

Stephen Hemminger May 30, 2023, 11:34 p.m. UTC
  I was looking at places in DPDK that are using rte_strlcpy which should be using strlcpy
directly instead.  Looking at this code in ipsec_mb, the use of strlcpy is actually
not needed at all.

/** Create a ring to place processed operations on */
static struct rte_ring
*ipsec_mb_qp_create_processed_ops_ring(
	struct ipsec_mb_qp *qp, unsigned int ring_size, int socket_id)
{
	struct rte_ring *r;
	char ring_name[RTE_CRYPTODEV_NAME_MAX_LEN];

	unsigned int n = rte_strlcpy(ring_name, qp->name, sizeof(ring_name));

	if (n >= sizeof(ring_name))
		return NULL;

	r = rte_ring_lookup(ring_name);

1. The maximum length name allowed for rte_ring is 30 characters which comes from
RTE_MEMZONE_NAMESIZE- sizeof(RTE_RING_MZ_PREFIX) + 1 = 32 - 3 + 1 = 30

2. RTE_CRYPTODEV_NAME_MAX_LEN is 64, qp->name is in struct ipsec_mb_qp is always the same size.

3. Ring create already does a copy of name, so making a copy here is not needed.

Therefore copying the name is not going to ever catch any errors. And if qp->name is
too long it won't fail until ring_create().

Would be better to just do something simpler like:
  

Comments

Ji, Kai June 20, 2023, 3:27 p.m. UTC | #1
Can you fix the commit messages with signed-off and Fixes

Acked-by: Kai Ji <kai.ji@intel.com<mailto:kai.ji@intel.com>>
  

Patch

diff --git a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
index 3e52f9567401..4af6592f12c5 100644
--- a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
+++ b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
@@ -185,12 +185,7 @@  static struct rte_ring
        struct ipsec_mb_qp *qp, unsigned int ring_size, int socket_id)
 {
        struct rte_ring *r;
-       char ring_name[RTE_CRYPTODEV_NAME_MAX_LEN];
-
-       unsigned int n = rte_strlcpy(ring_name, qp->name, sizeof(ring_name));
-
-       if (n >= sizeof(ring_name))
-               return NULL;
+       const char *ring_name = qp->name;
 
        r = rte_ring_lookup(ring_name);
        if (r) {