From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id BAC3D5A84 for ; Mon, 16 Mar 2015 18:05:09 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 16 Mar 2015 10:03:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,410,1422950400"; d="scan'208";a="680867336" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 16 Mar 2015 10:05:07 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t2GH57wM016951; Mon, 16 Mar 2015 17:05:07 GMT Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t2GH56sB019040; Mon, 16 Mar 2015 17:05:06 GMT Received: (from jmcnam2x@localhost) by sivswdev02.ir.intel.com with id t2GH56XQ019036; Mon, 16 Mar 2015 17:05:06 GMT From: John McNamara To: dev@dpdk.org Date: Mon, 16 Mar 2015 17:05:06 +0000 Message-Id: <1426525506-19003-1-git-send-email-john.mcnamara@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1426510564-19164-1-git-send-email-john.mcnamara@intel.com> References: <1426510564-19164-1-git-send-email-john.mcnamara@intel.com> Subject: [dpdk-dev] [PATCH v2] eal: fix Wbad-function-cast warning X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2015 17:05:10 -0000 Fix a warning when the rte_common.h header is included in a compilation using -Wbad-function-cast, such as in Open vSwitch where the following warning is emitted repeatedly: ../rte_common.h: In function 'rte_is_aligned': ../rte_common.h:184:9: warning: cast from function call of type 'uintptr_t' to non-matching type 'void *' [-Wbad-function-cast] This change fixes the issue in rte_common.h by using the RTE_ALIGN_FLOOR macro to get the aligned floor value with generic type casting. Also removed the rte_align_floor_int() function and replaced it with the RTE_PTR_ALIGN_FLOOR() macro. Signed-off-by: John McNamara --- app/test/test_common.c | 4 ++-- lib/librte_eal/common/include/rte_common.h | 21 +-------------------- lib/librte_malloc/malloc_elem.c | 2 +- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/app/test/test_common.c b/app/test/test_common.c index 4b71e7b..66e9109 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -122,8 +122,8 @@ test_align(void) for (i = 1; i <= MAX_NUM; i++) { /* align floor */ - if (rte_align_floor_int((uintptr_t)i, p) % p) - FAIL_ALIGN("rte_align_floor_int", i, p); + if (RTE_ALIGN_FLOOR((uintptr_t)i, p) % p) + FAIL_ALIGN("RTE_ALIGN_FLOOR", i, p); val = RTE_PTR_ALIGN_FLOOR((uintptr_t) i, p); if (ERROR_FLOOR(val, i, p)) diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 4971049..c0ab8b4 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -93,25 +93,6 @@ extern "C" { /*********** Macros/static functions for doing alignment ********/ -/** - * Function which rounds an unsigned int down to a given power-of-two value. - * Takes uintptr_t types as parameters, as this type of operation is most - * commonly done for pointer alignment. (See also RTE_ALIGN_FLOOR, - * RTE_ALIGN_CEIL, RTE_ALIGN, RTE_PTR_ALIGN_FLOOR, RTE_PTR_ALIGN_CEL, - * RTE_PTR_ALIGN macros) - * @param ptr - * The value to be rounded down - * @param align - * The power-of-two of which the result must be a multiple. - * @return - * Function returns a properly aligned value where align is a power-of-two. - * If align is not a power-of-two, result will be incorrect. - */ -static inline uintptr_t -rte_align_floor_int(uintptr_t ptr, uintptr_t align) -{ - return (ptr & ~(align - 1)); -} /** * Macro to align a pointer to a given power-of-two. The resultant @@ -120,7 +101,7 @@ rte_align_floor_int(uintptr_t ptr, uintptr_t align) * must be a power-of-two value. */ #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ - (typeof(ptr))rte_align_floor_int((uintptr_t)ptr, align) + ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align)) /** * Macro to align a value to a given power-of-two. The resultant value diff --git a/lib/librte_malloc/malloc_elem.c b/lib/librte_malloc/malloc_elem.c index fd0532e..a5e1248 100644 --- a/lib/librte_malloc/malloc_elem.c +++ b/lib/librte_malloc/malloc_elem.c @@ -90,7 +90,7 @@ elem_start_pt(struct malloc_elem *elem, size_t size, unsigned align) { const uintptr_t end_pt = (uintptr_t)elem + elem->size - MALLOC_ELEM_TRAILER_LEN; - const uintptr_t new_data_start = rte_align_floor_int((end_pt - size),align); + const uintptr_t new_data_start = RTE_ALIGN_FLOOR((end_pt - size), align); const uintptr_t new_elem_start = new_data_start - MALLOC_ELEM_HEADER_LEN; /* if the new start point is before the exist start, it won't fit */ -- 1.8.1.4