All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] eal: define container_of macro
@ 2016-11-20 10:05 Jan Blunck
  2016-11-20 10:05 ` [PATCH 2/7] eal: Helper to convert to struct rte_pci_device Jan Blunck
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Jan Blunck @ 2016-11-20 10:05 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, Jan Viktorin

This macro is based on Jan Viktorin's original patch but also checks the
type of the passed pointer against the type of the member.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
[jblunck@infradead.org: add type checking and __extension__]
Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_common.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index db5ac91..8dda3e2 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -331,6 +331,26 @@ rte_bsf32(uint32_t v)
 #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
 #endif
 
+/**
+ * Return pointer to the wrapping struct instance.
+ *
+ * Example:
+ *
+ *  struct wrapper {
+ *      ...
+ *      struct child c;
+ *      ...
+ *  };
+ *
+ *  struct child *x = obtain(...);
+ *  struct wrapper *w = container_of(x, struct wrapper, c);
+ */
+#ifndef container_of
+#define container_of(ptr, type, member)	__extension__ ({		\
+			typeof(((type *)0)->member) *_ptr = (ptr);	\
+			(type *)(((char *)_ptr) - offsetof(type, member)); })
+#endif
+
 #define _RTE_STR(x) #x
 /** Take a macro value and get a string version of it */
 #define RTE_STR(x) _RTE_STR(x)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-11-21 16:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-20 10:05 [PATCH 1/7] eal: define container_of macro Jan Blunck
2016-11-20 10:05 ` [PATCH 2/7] eal: Helper to convert to struct rte_pci_device Jan Blunck
2016-11-20 15:20   ` David Marchand
2016-11-21 16:57     ` Jan Blunck
2016-11-20 10:05 ` [PATCH 3/7] drivers: Use ETH_DEV_PCI_DEV() helper Jan Blunck
2016-11-20 10:05 ` [PATCH 4/7] virtio: Don't fill dev_info->driver_name Jan Blunck
2016-11-20 15:22   ` David Marchand
2016-11-21 16:34     ` Jan Blunck
2016-11-21 16:49       ` David Marchand
2016-11-21 16:52         ` Jan Blunck
2016-11-20 10:05 ` [PATCH 5/7] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle Jan Blunck
2016-11-20 10:05 ` [PATCH 6/7] virtio: Don't depend on struct rte_eth_dev's pci_dev Jan Blunck
2016-11-20 10:05 ` [PATCH 7/7] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get() Jan Blunck
2016-11-20 15:23   ` David Marchand

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.