DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: "Morten Brørup" <mb@smartsharesystems.com>
Cc: "Robin Jarry" <rjarry@redhat.com>, <dev@dpdk.org>
Subject: Re: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
Date: Wed, 25 Sep 2024 08:23:07 -0700	[thread overview]
Message-ID: <20240925082307.7162e556@fedora> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F72F@smartserver.smartshare.dk>

On Wed, 25 Sep 2024 17:21:12 +0200
Morten Brørup <mb@smartsharesystems.com> wrote:

> From: Morten Brørup <mb@smartsharesystems.com>
> To: "Robin Jarry" <rjarry@redhat.com>,  <dev@dpdk.org>
> Subject: RE: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
> Date: Wed, 25 Sep 2024 17:21:12 +0200
> 
> > From: Robin Jarry [mailto:rjarry@redhat.com]
> > Sent: Wednesday, 25 September 2024 10.00
> > 
> > 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@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;  
> 
> Suggest:
> 	__rte_mbuf_raw_sanity_check((struct rte_mbuf *)m);
> 	return (struct rte_mbuf *)m;

Another way to avoid the warning would be to use a union?

  reply	other threads:[~2024-09-25 15:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-25 14:00 Robin Jarry
2024-09-25 15:21 ` Morten Brørup
2024-09-25 15:23   ` Stephen Hemminger [this message]
2024-09-25 15:24     ` Robin Jarry
2024-09-25 15:40 ` [PATCH dpdk v2] " Robin Jarry
2024-09-25 15:47   ` Stephen Hemminger
2024-10-17 19:44     ` Thomas Monjalon
2024-10-17 14:17   ` Ali Alnubani
2024-09-26 16:38 ` [PATCH dpdk] " Patrick Robb

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=20240925082307.7162e556@fedora \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=mb@smartsharesystems.com \
    --cc=rjarry@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).