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

[PATCH 2/2] Ensure constness of target pointer type

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

This adds a check to ensure that the container_of() macro is not used to
cast away (remove) constness.

Signed-off-by: Jan Blunck <redacted>
---
 lib/librte_eal/common/include/rte_common.h | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index c421708..e057f6e 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -348,6 +348,8 @@ rte_bsf32(uint32_t v)
 #ifndef container_of
 #define container_of(ptr, type, member)	__extension__ ({		\
 			const typeof(((type *)0)->member) *_ptr = (ptr); \
+			__attribute__((unused)) type *_target_ptr =	\
+				(type *)(ptr);				\
 			(type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
 		})
 #endif
-- 
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