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 7D49FA0543; Thu, 22 Sep 2022 13:44:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 18AB240156; Thu, 22 Sep 2022 13:44:25 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 16C00400D7 for ; Thu, 22 Sep 2022 13:44:23 +0200 (CEST) Received: from dkrd2.smartsharesys.local ([192.168.4.12]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 22 Sep 2022 13:44:22 +0200 From: =?UTF-8?q?Morten=20Br=C3=B8rup?= To: thomas@monjalon.net, david.marchand@redhat.com Cc: dev@dpdk.org, =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v2] eal: Pointer alignment check improvements Date: Thu, 22 Sep 2022 13:44:13 +0200 Message-Id: <20220922114413.106291-1-mb@smartsharesystems.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220921142830.71272-1-mb@smartsharesystems.com> References: <20220921142830.71272-1-mb@smartsharesystems.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 22 Sep 2022 11:44:22.0483 (UTC) FILETIME=[A8716230:01D8CE78] 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 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 --- 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