]> xenbits.xensource.com Git - xen.git/commitdiff
tools: add container_of() macro to xen-tools/common-macros.h
authorJuergen Gross <jgross@suse.com>
Fri, 24 Mar 2023 10:13:43 +0000 (11:13 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 24 Mar 2023 10:13:43 +0000 (11:13 +0100)
Instead of having 3 identical copies of the definition of a
container_of() macro in different tools header files, add that macro
to xen-tools/common-macros.h and use that instead.

Delete the other copies of that macro.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
tools/include/xen-tools/common-macros.h
tools/tests/vpci/emul.h
tools/tests/x86_emulator/x86-emulate.h
tools/xenstore/list.h

index a372b9ecf263ed022871828e5a7d9308e2e0fa05..76b55bf62085b325d40d0f7fd6fd580920112bf4 100644 (file)
@@ -76,4 +76,9 @@
 #define __must_check __attribute__((__warn_unused_result__))
 #endif
 
+#define container_of(ptr, type, member) ({              \
+    typeof(((type *)0)->member) *mptr__ = (ptr);        \
+    (type *)((char *)mptr__ - offsetof(type, member));  \
+})
+
 #endif /* __XEN_TOOLS_COMMON_MACROS__ */
index d26e00b9d7fb1775d58d0461cfbbb89f371feba5..8c5bcadd5fef8ba52c7cb3869f09439f3ddb2c63 100644 (file)
 
 #include <xen-tools/common-macros.h>
 
-#define container_of(ptr, type, member) ({                      \
-        typeof(((type *)0)->member) *mptr = (ptr);              \
-                                                                \
-        (type *)((char *)mptr - offsetof(type, member));        \
-})
-
 #define smp_wmb()
 #define prefetch(x) __builtin_prefetch(x)
 #define ASSERT(x) assert(x)
index 46d4e43ceae429028cf226e323aad37e28741204..1af986f78d16b34c2b8033c4dd01d25b98174de7 100644 (file)
 
 #define cf_check /* No Control Flow Integriy checking */
 
-#define container_of(ptr, type, member) ({             \
-    typeof(((type *)0)->member) *mptr__ = (ptr);       \
-    (type *)((char *)mptr__ - offsetof(type, member)); \
-})
-
 #define AC_(n,t) (n##t)
 #define _AC(n,t) AC_(n,t)
 
index b17d13e0ec20464b9450730fdc9d498784f6b93e..a464a38b61c47440751d56d99ea70cd547292528 100644 (file)
@@ -3,6 +3,8 @@
 /* Taken from Linux kernel code, but de-kernelized for userspace. */
 #include <stddef.h>
 
+#include <xen-tools/common-macros.h>
+
 #undef LIST_HEAD_INIT
 #undef LIST_HEAD
 #undef INIT_LIST_HEAD
 #define LIST_POISON1  ((void *) 0x00100100)
 #define LIST_POISON2  ((void *) 0x00200200)
 
-#define container_of(ptr, type, member) ({                     \
-        typeof( ((type *)0)->member ) *__mptr = (ptr); \
-        (type *)( (char *)__mptr - offsetof(type,member) );})
-
 /*
  * Simple doubly linked list implementation.
  *