Thread (5 messages) 5 messages, 3 authors, 2017-03-08
STALE3424d

[PATCH 1/2] Fix container_of() macro to work with const members

From: Jan Blunck <hidden>
Date: 2017-02-14 14:36:17
Subsystem: library code, the rest · Maintainers: Andrew Morton, Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help