From 6cf14ce4ce6cb8a9a26c20769f20a8bf34a4491f Mon Sep 17 00:00:00 2001 From: Cyril Chemparathy Date: Mon, 22 Jun 2015 11:34:15 -0700 Subject: [PATCH] mempool: silence warning on pointer arithmetic 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 *). Signed-off-by: Cyril Chemparathy Acked-by: Olivier Matz --- 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 3cd5aab1a2..02699a18b5 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 f16019a218..6d4ce9abf4 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.20.1