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 02A5FA0C4C; Tue, 12 Oct 2021 21:40:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E920541124; Tue, 12 Oct 2021 21:40:07 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 677CA410FF for ; Tue, 12 Oct 2021 21:40:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634067606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Khp5W2gaAEX0tTqiNrQxMnoh+DnPsG1JpMy79Bn4JNY=; b=NnT4LgtsFs3Pb2f1w2QkBbrWRhcLi5YAx6eXXyVUHiJUbNM/Q0ftvB/lFjBTBqgfoFYbKE TkJg1B81S1JW3m6CeCEABni9W801AUTTZEDgh3vrcEO9rJ4LGYnvlaiX5wbepHng4+zmJR czhnbfOSAItwsY+bnyG+GGFlu9giT9Y= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-236-MxQOfe2CMxiYh_7owt0zkA-1; Tue, 12 Oct 2021 15:40:05 -0400 X-MC-Unique: MxQOfe2CMxiYh_7owt0zkA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F5BD79EDC; Tue, 12 Oct 2021 19:40:04 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id C78AD5D9D5; Tue, 12 Oct 2021 19:40:01 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: mdr@ashroe.eu, thomas@monjalon.net, Olivier Matz , Konstantin Ananyev Date: Tue, 12 Oct 2021 21:39:57 +0200 Message-Id: <20211012193957.21972-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH] mbuf: enforce no option for dynamic fields and flags 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 Sender: "dev" As stated in the API, dynamic field and flags should be created with no additional flag (simply in the API for future changes). Fix the dynamic flag register helper which was not enforcing it and add unit tests. Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags") Signed-off-by: David Marchand --- app/test/test_mbuf.c | 18 ++++++++++++++++++ lib/mbuf/rte_mbuf_dyn.c | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 9a248dfaea..82777109dc 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -2577,6 +2577,16 @@ test_mbuf_dyn(struct rte_mempool *pktmbuf_pool) .align = 3, .flags = 0, }; + const struct rte_mbuf_dynfield dynfield_fail_flag = { + .name = "test-dynfield", + .size = sizeof(uint8_t), + .align = __alignof__(uint8_t), + .flags = 1, + }; + const struct rte_mbuf_dynflag dynflag_fail_flag = { + .name = "test-dynflag", + .flags = 1, + }; const struct rte_mbuf_dynflag dynflag = { .name = "test-dynflag", .flags = 0, @@ -2638,6 +2648,14 @@ test_mbuf_dyn(struct rte_mempool *pktmbuf_pool) if (ret != -1) GOTO_FAIL("dynamic field creation should fail (not avail)"); + ret = rte_mbuf_dynfield_register(&dynfield_fail_flag); + if (ret != -1) + GOTO_FAIL("dynamic field creation should fail (invalid flag)"); + + ret = rte_mbuf_dynflag_register(&dynflag_fail_flag); + if (ret != -1) + GOTO_FAIL("dynamic flag creation should fail (invalid flag)"); + flag = rte_mbuf_dynflag_register(&dynflag); if (flag == -1) GOTO_FAIL("failed to register dynamic flag, flag=%d: %s", diff --git a/lib/mbuf/rte_mbuf_dyn.c b/lib/mbuf/rte_mbuf_dyn.c index ca46eb279e..d55e162a68 100644 --- a/lib/mbuf/rte_mbuf_dyn.c +++ b/lib/mbuf/rte_mbuf_dyn.c @@ -498,6 +498,10 @@ rte_mbuf_dynflag_register_bitnum(const struct rte_mbuf_dynflag *params, { int ret; + if (params->flags != 0) { + rte_errno = EINVAL; + return -1; + } if (req >= RTE_SIZEOF_FIELD(struct rte_mbuf, ol_flags) * CHAR_BIT && req != UINT_MAX) { rte_errno = EINVAL; -- 2.23.0