[PATCH v2] eal: Pointer alignment check improvements
Morten Brørup
mb at smartsharesystems.com
Thu Sep 22 13:44:13 CEST 2022
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 at 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;
}
/*********** Macros for compile type checks ********/
--
2.17.1
More information about the dev
mailing list