From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <olivier.matz@6wind.com> Received: from mail.droids-corp.org (zoll.droids-corp.org [94.23.50.67]) by dpdk.org (Postfix) with ESMTP id 7DB6AC896 for <dev@dpdk.org>; Fri, 19 Jun 2015 17:57:59 +0200 (CEST) Received: from was59-1-82-226-113-214.fbx.proxad.net ([82.226.113.214] helo=[192.168.0.10]) by mail.droids-corp.org with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from <olivier.matz@6wind.com>) id 1Z5yka-0007Cf-A9; Fri, 19 Jun 2015 18:02:46 +0200 Message-ID: <55843C43.6090204@6wind.com> Date: Fri, 19 Jun 2015 17:58:59 +0200 From: Olivier MATZ <olivier.matz@6wind.com> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0 MIME-Version: 1.0 To: Cyril Chemparathy <cchemparathy@ezchip.com>, dev@dpdk.org References: <1430324134-25654-1-git-send-email-cchemparathy@ezchip.com> <1430324134-25654-9-git-send-email-cchemparathy@ezchip.com> In-Reply-To: <1430324134-25654-9-git-send-email-cchemparathy@ezchip.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 08/10] librte_mbuf: Add rte_pktmbuf_mtod_offset() 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: Fri, 19 Jun 2015 15:57:59 -0000 On 04/29/2015 06:15 PM, Cyril Chemparathy wrote: > 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. > > Signed-off-by: Cyril Chemparathy <cchemparathy@ezchip.com> > --- > lib/librte_mbuf/rte_mbuf.h | 20 +++++++++++++++++++- > 1 file changed, 19 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h > index 5ddd8dd..e8f1bf4 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> > @@ -1071,6 +1072,23 @@ 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 m_headlen(m) is large enough to > + * read its data. Small comment here: m_headlen(m) should be replaced by "the length of the first segment". Indeed, there is no m_headlen() function (I see that it is coming from a copy/paste of the mtod() comment). Could you also fix it by the way? > + * > + * @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 > @@ -1082,7 +1100,7 @@ static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m) > * @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. >