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 151BF45A2A; Wed, 25 Sep 2024 16:00:32 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9DC074025D; Wed, 25 Sep 2024 16:00:31 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 0DC4C400EF for ; Wed, 25 Sep 2024 16:00:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727272829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sU52LpyXj+3t0IR4Z1U2+oVX4rQDQNkaoeATDQpv49s=; b=AtpvbqiWimp84/yUQGpXgsuQlHYSS4ousS+yWMK1liamgOGZy0s614pBFSKRB/sfNhicq6 Tu3jl8DDupJYZwWaX/+gcZk+CuH3ePJmXOV07L6dL50S7ShCQzp3kRnKdl0q0SfsNr8ZXF x+FwALlKhYVy6tiOlizzERzljgMu5zg= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-353-1uopEeTDPymf4pzTFJm1hA-1; Wed, 25 Sep 2024 10:00:27 -0400 X-MC-Unique: 1uopEeTDPymf4pzTFJm1hA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9AE6619560BD for ; Wed, 25 Sep 2024 14:00:26 +0000 (UTC) Received: from ringo.redhat.com (unknown [10.22.0.17]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AFAC419560AA; Wed, 25 Sep 2024 14:00:25 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org Subject: [PATCH dpdk] mbuf: fix strict aliasing error in allocator Date: Wed, 25 Sep 2024 10:00:22 -0400 Message-ID: <20240925140021.46320-2-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 When building an application with -fstrict-aliasing -Wstrict-aliasing=2, we get errors triggered by rte_mbuf_raw_alloc() which is called inline from rte_pktmbuf_alloc(). ../dpdk/lib/mbuf/rte_mbuf.h: In function ‘rte_mbuf_raw_alloc’: ../dpdk/lib/mbuf/rte_mbuf.h:600:42: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing] 600 | if (rte_mempool_get(mp, (void **)&m) < 0) | ^~ Avoid incorrect casting by changing the type of the returned variable. Signed-off-by: Robin Jarry --- lib/mbuf/rte_mbuf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h index babe16c72ccb..bab1fb94d41d 100644 --- a/lib/mbuf/rte_mbuf.h +++ b/lib/mbuf/rte_mbuf.h @@ -595,9 +595,9 @@ __rte_mbuf_raw_sanity_check(__rte_unused const struct rte_mbuf *m) */ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp) { - struct rte_mbuf *m; + void *m; - if (rte_mempool_get(mp, (void **)&m) < 0) + if (rte_mempool_get(mp, &m) < 0) return NULL; __rte_mbuf_raw_sanity_check(m); return m; -- 2.46.1