Skip to contentSkip to conversation

use offsetof for rb_entry

PATCH In review [email protected] 2 participants 2 messages Oct 7, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use offsetof for rb_entry

Use, in the rb_entry definition, the offsetof macro instead of reinventing the wheel.

---

 linux-2.6.9-current-paolo/include/linux/rbtree.h |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)
include/linux/rbtree.h renamed from include/linux/rbtree.h~use-offsetof-rb_entry +1 -1
diff -puN include/linux/rbtree.h~use-offsetof-rb_entry include/linux/rbtree.h
@@ -114,7 +114,7 @@ struct rb_root
 
 #define RB_ROOT	(struct rb_root) { NULL, }
 #define	rb_entry(ptr, type, member)					\
-	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+	((type *)((char *)(ptr) - offsetof(type, member)))
 
 extern void rb_insert_color(struct rb_node *, struct rb_root *);
 extern void rb_erase(struct rb_node *, struct rb_root *);

_

#1 lore raw
Quoted 3 lines · On Thu, Oct 07, 2004 at 07:53:42PM +0200, [email protected] wrote:

Use, in the rb_entry definition, the offsetof macro instead of reinventing the wheel.

Or just use container_of - which has the additional benefit of beeing typesafe.