From patchwork Thu Sep 22 13:27:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Morten_Br=C3=B8rup?= X-Patchwork-Id: 116652 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 882C2A0543; Thu, 22 Sep 2022 15:27:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 79C5540E28; Thu, 22 Sep 2022 15:27:42 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 8F272400D7 for ; Thu, 22 Sep 2022 15:27:40 +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 15:27:40 +0200 From: =?utf-8?q?Morten_Br=C3=B8rup?= To: thomas@monjalon.net, david.marchand@redhat.com, bruce.richardson@intel.com Cc: dev@dpdk.org, =?utf-8?q?Morten_Br=C3=B8rup?= Subject: [PATCH v3] eal: Pointer alignment check improvements Date: Thu, 22 Sep 2022 15:27:30 +0200 Message-Id: <20220922132730.5178-1-mb@smartsharesystems.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D8734D@smartserver.smartshare.dk> References: <98CBD80474FA8B44BF855DF32C47DC35D8734D@smartserver.smartshare.dk> MIME-Version: 1.0 X-OriginalArrivalTime: 22 Sep 2022 13:27:40.0287 (UTC) FILETIME=[169F38F0:01D8CE87] 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. v3: - Make the uintptr_t const to avoid potential future warnings. (Bruce) v2: - Remove compiler attribute ((const)) from function; it was a coding style issue. Signed-off-by: Morten Brørup Acked-by: Bruce Richardson --- 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 ((const uintptr_t)ptr & (align - 1)) == 0; } /*********** Macros for compile type checks ********/