DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cyril Chemparathy <cchemparathy@ezchip.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v4 7/9] librte_mbuf: Add rte_pktmbuf_mtod_offset()
Date: Mon, 22 Jun 2015 11:34:21 -0700	[thread overview]
Message-ID: <1434998063-15739-8-git-send-email-cchemparathy@ezchip.com> (raw)
In-Reply-To: <1434998063-15739-1-git-send-email-cchemparathy@ezchip.com>

There are a number of instances in the code where rte_pktmbuf_mtod()
is used to get the mbuf data pointer, only to add an offset before
casting the result to some other header type.  This patch adds a new
rte_pktmbuf_mtod_offset() macro to eliminate these awful double cast
situations.

Change-Id: I4dec35a15e44a7b8c767559a8d3b294177f39552
Signed-off-by: Cyril Chemparathy <cchemparathy@ezchip.com>
---
 lib/librte_mbuf/rte_mbuf.h | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index 6efd2b5..396963c 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -54,6 +54,7 @@
  */
 
 #include <stdint.h>
+#include <rte_common.h>
 #include <rte_mempool.h>
 #include <rte_memory.h>
 #include <rte_atomic.h>
@@ -1080,18 +1081,35 @@ static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m)
 }
 
 /**
+ * A macro that points to an offset into the data in the mbuf.
+ *
+ * The returned pointer is cast to type t. Before using this
+ * function, the user must ensure that the first segment is large
+ * enough to accomodate its data.
+ *
+ * @param m
+ *   The packet mbuf.
+ * @param o
+ *   The offset into the mbuf data.
+ * @param t
+ *   The type to cast the result into.
+ */
+#define rte_pktmbuf_mtod_offset(m, t, o)	\
+	((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
+
+/**
  * A macro that points to the start of the data in the mbuf.
  *
  * The returned pointer is cast to type t. Before using this
- * function, the user must ensure that m_headlen(m) is large enough to
- * read its data.
+ * function, the user must ensure that the first segment is large
+ * enough to accomodate its data.
  *
  * @param m
  *   The packet mbuf.
  * @param t
  *   The type to cast the result into.
  */
-#define rte_pktmbuf_mtod(m, t) ((t)((char *)(m)->buf_addr + (m)->data_off))
+#define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
 
 /**
  * A macro that returns the length of the packet.
-- 
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 ` [dpdk-dev] [PATCH v4 4/9] hash: " Cyril Chemparathy
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 ` Cyril Chemparathy [this message]
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-8-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).