diff mbox

[dpdk-dev,1/2] Fix container_of() macro to work with const members

Message ID 1487082966-21074-1-git-send-email-jblunck@infradead.org (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Jan Blunck Feb. 14, 2017, 2:36 p.m. UTC
This fixes the usage of structure members that are declared const to get
a pointer to the embedding parent structure.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_common.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Jan Blunck Feb. 27, 2017, 2:28 p.m. UTC | #1
On Tue, Feb 14, 2017 at 3:36 PM, Jan Blunck <jblunck@infradead.org> wrote:
> This fixes the usage of structure members that are declared const to get
> a pointer to the embedding parent structure.

Ping. Is anyone willing to review this?

Thanks,
Jan

>
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> ---
>  lib/librte_eal/common/include/rte_common.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> index 8dda3e2..c421708 100644
> --- a/lib/librte_eal/common/include/rte_common.h
> +++ b/lib/librte_eal/common/include/rte_common.h
> @@ -347,8 +347,9 @@ rte_bsf32(uint32_t v)
>   */
>  #ifndef container_of
>  #define container_of(ptr, type, member)        __extension__ ({                \
> -                       typeof(((type *)0)->member) *_ptr = (ptr);      \
> -                       (type *)(((char *)_ptr) - offsetof(type, member)); })
> +                       const typeof(((type *)0)->member) *_ptr = (ptr); \
> +                       (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
> +               })
>  #endif
>
>  #define _RTE_STR(x) #x
> --
> 2.7.4
>
Bruce Richardson Feb. 27, 2017, 3:14 p.m. UTC | #2
On Mon, Feb 27, 2017 at 03:28:14PM +0100, Jan Blunck wrote:
> On Tue, Feb 14, 2017 at 3:36 PM, Jan Blunck <jblunck@infradead.org> wrote:
> > This fixes the usage of structure members that are declared const to get
> > a pointer to the embedding parent structure.
> 
> Ping. Is anyone willing to review this?
>
Looks ok to me.

Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Thomas Monjalon March 8, 2017, 2:01 p.m. UTC | #3
2017-02-27 15:14, Bruce Richardson:
> On Mon, Feb 27, 2017 at 03:28:14PM +0100, Jan Blunck wrote:
> > On Tue, Feb 14, 2017 at 3:36 PM, Jan Blunck <jblunck@infradead.org> wrote:
> > > This fixes the usage of structure members that are declared const to get
> > > a pointer to the embedding parent structure.
> > 
> > Ping. Is anyone willing to review this?
> >
> Looks ok to me.
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks
diff mbox

Patch

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 8dda3e2..c421708 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -347,8 +347,9 @@  rte_bsf32(uint32_t v)
  */
 #ifndef container_of
 #define container_of(ptr, type, member)	__extension__ ({		\
-			typeof(((type *)0)->member) *_ptr = (ptr);	\
-			(type *)(((char *)_ptr) - offsetof(type, member)); })
+			const typeof(((type *)0)->member) *_ptr = (ptr); \
+			(type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
+		})
 #endif
 
 #define _RTE_STR(x) #x