From patchwork Thu Sep 22 11:44:13 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: 116646 X-Patchwork-Delegate: david.marchand@redhat.com 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 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_Br=C3=B8rup?= To: thomas@monjalon.net, david.marchand@redhat.com Cc: dev@dpdk.org, =?utf-8?q?Morten_Br=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 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 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 ((uintptr_t)ptr & (align - 1)) == 0; } /*********** Macros for compile type checks ********/