From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 121F042BE7; Wed, 31 May 2023 01:35:04 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DF99840E2D; Wed, 31 May 2023 01:35:03 +0200 (CEST) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mails.dpdk.org (Postfix) with ESMTP id F1CA940E25 for ; Wed, 31 May 2023 01:35:01 +0200 (CEST) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1b04706c974so22362455ad.2 for ; Tue, 30 May 2023 16:35:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1685489701; x=1688081701; h=content-transfer-encoding:mime-version:message-id:subject:cc:to :from:date:from:to:cc:subject:date:message-id:reply-to; bh=2TMC2b6VOcix/iSVzOjwagFvjZsWh+TgsiP9ER6qbRM=; b=eoCG4klfmmWaXpjptrqcdb3ocUVgi8Jl11lua60H3Vdp3AIjjTvCpwVFmxP8DTDWbl FZC9InfUwguXx5VH2K3PMKN/s7dFiATa6igdfVYPr7NXcatR36mHw+TBWqmg/KxBnQ1u wNsCob2NuwvtNtRnRTPhVILy7e1YrvWYBbe8BJTBr99dCm6Mv87VB8vPBrNhnfRGzlJG nxijwvdttoYgC8vK4GRLO1O/iU88o1FIupIZ83GGWnfozSCnh0JF+JOPL+UugNTUYPcV s7vTYe/akEKVUQUH4p1S00GQfSW868hj1tg1ccthQPmoxUpk6Okpp/iwWxU5nCvhPb1d RK9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685489701; x=1688081701; h=content-transfer-encoding:mime-version:message-id:subject:cc:to :from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2TMC2b6VOcix/iSVzOjwagFvjZsWh+TgsiP9ER6qbRM=; b=U5WaYHSmSk9NluFNE7x72kVOVArfayjm4A921dSIhLQ3dMr8xTlx9oBiVLBWWIV4D0 85LIrti5u2ZMY3502URlrVf9UF/IsiQ0x6k35InifcIhnZZ77x78Dp1/D1OSJ8gD1B98 AzSPr7C1ksfWoLVe1V6Ox4Rxng+IKkZhaF9DhQUAYVc1HSPebMFlOnF0dms42gmto2AS 6mNydlncX3Qbu+OVAJj4kkYZmHtAMN6eQViDDjKR9hRgcK78maVTImuwdE73MxsoiQ8o gz7KSrGhAiRrimr9MUfj+nOWhzrftmzk9ilYQ8c/dbVYcjLG/1rJl3/3RatFvVT1sPHw 9fKQ== X-Gm-Message-State: AC+VfDxMuXT98z+w/UeE6FbjZS70zBB9r1QmCydSz01WojeWhqlfVPcw dEC3vt3z8q8coyq+gr/i2ENSjg== X-Google-Smtp-Source: ACHHUZ5Na2+MfwCgZrs0aQcZTORzuNLZU2feS2YJjlC4THTxkEPyJafzAG/2AmiZLsyZXA917tlkFw== X-Received: by 2002:a17:902:e883:b0:1b0:3c2a:2b4e with SMTP id w3-20020a170902e88300b001b03c2a2b4emr5113153plg.8.1685489701047; Tue, 30 May 2023 16:35:01 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id g9-20020a170902868900b001ae8b4dc49bsm10826684plo.13.2023.05.30.16.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 16:34:59 -0700 (PDT) Date: Tue, 30 May 2023 16:34:57 -0700 From: Stephen Hemminger To: Fan Zhang Cc: dev@dpdk.org Subject: ring name length simplification in ipsec_mb_qp_create_processed_ops_ring Message-ID: <20230530163457.665dd69a@hermes.local> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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) {