From: Bruce Richardson <bruce.richardson@intel.com>
To: "Morten Brørup" <mb@smartsharesystems.com>
Cc: <thomas@monjalon.net>, <david.marchand@redhat.com>, <dev@dpdk.org>
Subject: Re: [PATCH v2] eal: Pointer alignment check improvements
Date: Thu, 22 Sep 2022 12:59:27 +0100 [thread overview]
Message-ID: <YyxOH77ift1PqN8K@bricha3-MOBL.ger.corp.intel.com> (raw)
In-Reply-To: <YyxMijdAf2k1GHBN@bricha3-MOBL.ger.corp.intel.com>
On Thu, Sep 22, 2022 at 12:52:42PM +0100, Bruce Richardson wrote:
> On Thu, Sep 22, 2022 at 01:44:13PM +0200, Morten Brørup wrote:
> > Checking a const pointer for alignment would emit a warning about the
> > const qualifier being discarded.
> >
> > No need to calculate the aligned pointer; just check the last bits of the
> > pointer.
> >
> > v2:
> > - Remove compiler attribute ((const)) from function;
> > it was a coding style issue.
> >
> > Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
> > ---
> > lib/eal/include/rte_common.h | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
> > index 2e22c1b955..ed81e0db0a 100644
> > --- a/lib/eal/include/rte_common.h
> > +++ b/lib/eal/include/rte_common.h
> > @@ -404,9 +404,9 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
> > * True(1) where the pointer is correctly aligned, false(0) otherwise
> > */
> > static inline int
> > -rte_is_aligned(void *ptr, unsigned align)
> > +rte_is_aligned(const void * const __rte_restrict ptr, const unsigned int align)
> > {
> > - return RTE_PTR_ALIGN(ptr, align) == ptr;
> > + return ((uintptr_t)ptr & (align - 1)) == 0;
>
> Are we confident that in future, or using come compiler settings, we won't
> get an error due to using "uintptr_t" rather than "const uintptr_t" in the
> cast? I would put a const in there myself, just to be safe.
>
> A further point, only-semi-related to this patch, which is fine as-is:
> looking at the code for the various macros in rte_common.h:
> * The various macros for working on pointers can can probably be converted
> to functions, since they don't need to work with variable-sized types.
> * We can then see about properly ensuring those inline functions are
> const-correct.
>
Actually, on further investigation in trying this, it appears that the
macros are used in a number of places with integer data too, despite the
"PTR" in the name, so things are best alone for now, I think.
/Bruce
next prev parent reply other threads:[~2022-09-22 11:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 14:28 [PATCH] " Morten Brørup
2022-09-22 11:44 ` [PATCH v2] " Morten Brørup
2022-09-22 11:52 ` Bruce Richardson
2022-09-22 11:59 ` Bruce Richardson [this message]
2022-09-22 13:00 ` Morten Brørup
2022-09-22 13:27 ` [PATCH v3] " Morten Brørup
2022-09-22 13:38 ` Bruce Richardson
2022-09-22 20:54 ` Morten Brørup
2022-09-23 8:24 ` Bruce Richardson
2022-09-23 8:25 ` [PATCH v2] " Bruce Richardson
2022-09-30 8:38 ` David Marchand
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=YyxOH77ift1PqN8K@bricha3-MOBL.ger.corp.intel.com \
--to=bruce.richardson@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
--cc=thomas@monjalon.net \
/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).