All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Fan Zhang <fanzhang.oss@gmail.com>
Cc: dev@dpdk.org
Subject: ring name length simplification  in ipsec_mb_qp_create_processed_ops_ring
Date: Tue, 30 May 2023 16:34:57 -0700	[thread overview]
Message-ID: <20230530163457.665dd69a@hermes.local> (raw)

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:

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) {

             reply	other threads:[~2023-05-30 23:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30 23:34 Stephen Hemminger [this message]
2023-06-20 15:27 ` ring name length simplification in ipsec_mb_qp_create_processed_ops_ring Ji, Kai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230530163457.665dd69a@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=fanzhang.oss@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.