DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cyril Chemparathy <cchemparathy@ezchip.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v4 4/9] hash: silence -Wcast-align on pointer arithmetic
Date: Mon, 22 Jun 2015 11:34:18 -0700	[thread overview]
Message-ID: <1434998063-15739-5-git-send-email-cchemparathy@ezchip.com> (raw)
In-Reply-To: <1434998063-15739-1-git-send-email-cchemparathy@ezchip.com>

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

  parent reply	other threads:[~2015-06-22 18:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-22 18:34 [dpdk-dev] [PATCH v4 0/9] Improve cast alignment for strict aligned machines Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 1/9] mempool: silence -Wcast-align on pointer arithmetic Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 2/9] mbuf: " Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 3/9] ethdev: " Cyril Chemparathy
2015-06-22 18:34 ` Cyril Chemparathy [this message]
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 5/9] eal: add and use unaligned integer types Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 6/9] app/test-pmd: pack simple_gre_hdr Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 7/9] librte_mbuf: Add rte_pktmbuf_mtod_offset() Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 8/9] librte_mbuf: Add transform for rte_pktmbuf_mtod_offset() Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 9/9] librte_mbuf: Apply mtod-offset.cocci transform Cyril Chemparathy
2015-06-23 15:36 ` [dpdk-dev] [PATCH v4 0/9] Improve cast alignment for strict aligned machines Olivier MATZ
2015-06-23 17:36   ` Cyril Chemparathy
2015-06-24 10:04   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434998063-15739-5-git-send-email-cchemparathy@ezchip.com \
    --to=cchemparathy@ezchip.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).