[PATCH dpdk] mbuf: fix strict aliasing error in allocator
Robin Jarry
rjarry at redhat.com
Wed Sep 25 16:00:22 CEST 2024
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 <rjarry at redhat.com>
---
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
More information about the dev
mailing list