eal: fix container_of macro for const members
authorJan Blunck <jblunck@infradead.org>
Tue, 14 Feb 2017 14:36:05 +0000 (15:36 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 8 Mar 2017 12:48:36 +0000 (13:48 +0100)
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>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
lib/librte_eal/common/include/rte_common.h

index 8dda3e2..c421708 100644 (file)
@@ -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