From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wj0-f196.google.com (mail-wj0-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id 810D63DC for ; Tue, 13 Dec 2016 23:24:34 +0100 (CET) Received: by mail-wj0-f196.google.com with SMTP id xy5so288763wjc.1 for ; Tue, 13 Dec 2016 14:24:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=DMn4B6cYebJQQOL/mRrFp+3CP9Ivp8lopYQ9KIafVdU=; b=BZFmjQOjeS+Is+ggqipQEKfJGjIkl38osEWLR84vObA/QgjeGsAvC29LaJGQRdDrWk sFV/Sz7lpBg0ZTyvVlO5oOMXdK5UvJp2Npo9bxmTcXiC/eLvQnT72tRGzf7h2WJbj1ea NorS7RMdP15lVfr7wNrQAimB5OORSASBqqK9TAM7BrMvIToClbhz7eaIhdzyt4WzVh9T TM7aYlNA8Eh/7sBdu3XmHb9GOVl3n20dQO/FYJ0ADl2q1pC0NnscTbhIuavt2pdfjlyE 0QHstt7V7Wpd4BpMPduhfnqdokMZ6SzNhs0miRI7p4PrKwVLnv3dcMCY1U5GSyutgsLm 4jXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=DMn4B6cYebJQQOL/mRrFp+3CP9Ivp8lopYQ9KIafVdU=; b=ISdHhFGSYMRSiTQOyR1VwdE1odACSBHgFYQXCx7mrUnLh5UqEj+qSJ4qfdUnXtMhXH mVP/9Fkr1lr148BtSRlb1htEMtEeu20nREl9cH6gyJ5Vm0ouKc1XlSlm1wMQeLDfL9gp HA2nmyfFshY4gn5gMFVLzO8tBQ/nEFHCuOnY0vbJlHT4iLiOrs4MQvpmqX6cINuBzG+D zeR0wzAEdcOwINmSyJaxxV1vHqY6BnUPZgKsTZOVNogMZ4ZHbmTlz+ehyTZJL6GfCciw G4u0toiojBky3Tdx6LZfn6im/eWwKzp4xZHKhjeHKgtUrIip2DKcTzRp8DQGM286KbB8 5MZw== X-Gm-Message-State: AKaTC03QL0qTk7P+uCEe8QvX2TTu4iF666EyqGxmarq8gC3tDD5ED73S6Pncw2GavlOgWRRVDCToivlHG38woA== X-Received: by 10.194.127.104 with SMTP id nf8mr56599367wjb.39.1481667873893; Tue, 13 Dec 2016 14:24:33 -0800 (PST) MIME-Version: 1.0 Sender: jblunck@gmail.com Received: by 10.28.63.83 with HTTP; Tue, 13 Dec 2016 14:24:33 -0800 (PST) In-Reply-To: <1481636232-2300-2-git-send-email-shreyansh.jain@nxp.com> References: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com> <1481636232-2300-1-git-send-email-shreyansh.jain@nxp.com> <1481636232-2300-2-git-send-email-shreyansh.jain@nxp.com> From: Jan Blunck Date: Tue, 13 Dec 2016 23:24:33 +0100 X-Google-Sender-Auth: XVYTyInWi7TQcJ24LSIYPxTUM8s Message-ID: To: Shreyansh Jain Cc: dev@dpdk.org, David Marchand , Thomas Monjalon , Ferruh Yigit , jianbo.liu@linaro.org, Jan Viktorin Content-Type: text/plain; charset=UTF-8 Subject: Re: [dpdk-dev] [PATCH v2 01/12] eal: define container_of macro X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Dec 2016 22:24:34 -0000 On Tue, Dec 13, 2016 at 2:37 PM, Shreyansh Jain wrote: > From: Jan Blunck > > This macro is based on Jan Viktorin's original patch but also checks the > type of the passed pointer against the type of the member. > > Signed-off-by: Jan Viktorin > [shreyansh.jain@nxp.com: Fix checkpatch error] > Signed-off-by: Shreyansh Jain > [jblunck@infradead.org: add type checking and __extension__] > Signed-off-by: Jan Blunck > > -- > v2: > - fix checkpatch error > --- > lib/librte_eal/common/include/rte_common.h | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h > index db5ac91..3eb8d11 100644 > --- a/lib/librte_eal/common/include/rte_common.h > +++ b/lib/librte_eal/common/include/rte_common.h > @@ -331,6 +331,27 @@ rte_bsf32(uint32_t v) > #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) > #endif > > +/** > + * Return pointer to the wrapping struct instance. > + * > + * Example: > + * > + * struct wrapper { > + * ... > + * struct child c; > + * ... > + * }; > + * > + * struct child *x = obtain(...); > + * struct wrapper *w = container_of(x, struct wrapper, c); > + */ > +#ifndef container_of > +#define container_of(ptr, type, member) (__extension__ ({ \ > + typeof(((type *)0)->member) * _ptr = (ptr); \ > + (type *)(((char *)_ptr) - offsetof(type, member));\ > + })) This is a checkpatch false positive. It should be fine to ignore this. IIRC we already discussed this before. > +#endif > + > #define _RTE_STR(x) #x > /** Take a macro value and get a string version of it */ > #define RTE_STR(x) _RTE_STR(x) > -- > 2.7.4 >