From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sclab-apps-2.localdomain (sc-fw1.tilera.com [12.218.212.162]) by dpdk.org (Postfix) with ESMTP id E59A3C33C for ; Mon, 22 Jun 2015 20:34:31 +0200 (CEST) X-CheckPoint: {55885535-3-A3D4DA0C-C0000002} Received: by sclab-apps-2.localdomain (Postfix, from userid 1318) id 756D9220489; Mon, 22 Jun 2015 11:34:29 -0700 (PDT) From: Cyril Chemparathy To: dev@dpdk.org Date: Mon, 22 Jun 2015 11:34:15 -0700 Message-Id: <1434998063-15739-2-git-send-email-cchemparathy@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1434998063-15739-1-git-send-email-cchemparathy@ezchip.com> References: <1434998063-15739-1-git-send-email-cchemparathy@ezchip.com> Subject: [dpdk-dev] [PATCH v4 1/9] mempool: silence -Wcast-align on pointer arithmetic 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, 22 Jun 2015 18:34:43 -0000 Translating from a mempool object to the mempool pointer does not break alignment constraints. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_SUB(), thereby silencing the compiler by casting through (void *). Change-Id: I4a67c9aa1bf012a0bf860d21bb8105db89062c76 Signed-off-by: Cyril Chemparathy --- lib/librte_mempool/rte_mempool.c | 2 +- lib/librte_mempool/rte_mempool.h | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index f592dc7..002d3a8 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -136,7 +136,7 @@ mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx, obj = (char *)obj + mp->header_size; /* set mempool ptr in header */ - hdr = (struct rte_mempool_objhdr *)((char *)obj - sizeof(*hdr)); + hdr = RTE_PTR_SUB(obj, sizeof(*hdr)); hdr->mp = mp; #ifdef RTE_LIBRTE_MEMPOOL_DEBUG diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index a8054e1..380d60b 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -262,15 +262,13 @@ struct rte_mempool { /* return the header of a mempool object (internal) */ static inline struct rte_mempool_objhdr *__mempool_get_header(void *obj) { - return (struct rte_mempool_objhdr *)((char *)obj - - sizeof(struct rte_mempool_objhdr)); + return RTE_PTR_SUB(obj, sizeof(struct rte_mempool_objhdr)); } /* return the trailer of a mempool object (internal) */ static inline struct rte_mempool_objtlr *__mempool_get_trailer(void *obj) { - return (struct rte_mempool_objtlr *)((char *)obj - - sizeof(struct rte_mempool_objtlr)); + return RTE_PTR_SUB(obj, sizeof(struct rte_mempool_objtlr)); } /** -- 2.1.2