From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <cchemparathy@ezchip.com>
Received: from sclab-apps-2.localdomain (sc-fw1.tilera.com [12.218.212.162])
 by dpdk.org (Postfix) with ESMTP id 9577BC880
 for <dev@dpdk.org>; Mon, 22 Jun 2015 20:34:44 +0200 (CEST)
X-CheckPoint: {55885542-2-A3D4DA0C-C0000002}
Received: by sclab-apps-2.localdomain (Postfix, from userid 1318)
 id A92DF220501; Mon, 22 Jun 2015 11:34:29 -0700 (PDT)
From: Cyril Chemparathy <cchemparathy@ezchip.com>
To: dev@dpdk.org
Date: Mon, 22 Jun 2015 11:34:18 -0700
Message-Id: <1434998063-15739-5-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 4/9] hash: 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 <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Jun 2015 18:34:52 -0000

Since sig_tbl_bucket_size and key_tbl_key_size are explicitly aligned
at initialization, offset dereferences in the hash table code cannot
possibly be unaligned.  However, the compiler is unaware of this fact
and complains on -Wcast-align.  This patch modifies the code to use
RTE_PTR_ADD(), thereby silencing the compiler by casting through (void
*).

Change-Id: Ia7102cf3f870752743cfe9f4443a3e53cd99bac1
Signed-off-by: Cyril Chemparathy <cchemparathy@ezchip.com>
---
 lib/librte_hash/rte_hash.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c
index 9245716..67dff5b 100644
--- a/lib/librte_hash/rte_hash.c
+++ b/lib/librte_hash/rte_hash.c
@@ -96,23 +96,23 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
 static inline hash_sig_t *
 get_sig_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index)
 {
-	return (hash_sig_t *)
-			&(h->sig_tbl[bucket_index * h->sig_tbl_bucket_size]);
+	return RTE_PTR_ADD(h->sig_tbl, (bucket_index *
+					h->sig_tbl_bucket_size));
 }
 
 /* Returns a pointer to the first key in specified bucket. */
 static inline uint8_t *
 get_key_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index)
 {
-	return (uint8_t *) &(h->key_tbl[bucket_index * h->bucket_entries *
-				     h->key_tbl_key_size]);
+	return RTE_PTR_ADD(h->key_tbl, (bucket_index * h->bucket_entries *
+					h->key_tbl_key_size));
 }
 
 /* Returns a pointer to a key at a specific position in a specified bucket. */
 static inline void *
 get_key_from_bucket(const struct rte_hash *h, uint8_t *bkt, uint32_t pos)
 {
-	return (void *) &bkt[pos * h->key_tbl_key_size];
+	return RTE_PTR_ADD(bkt, pos * h->key_tbl_key_size);
 }
 
 /* Does integer division with rounding-up of result. */
-- 
2.1.2