container_of: Avoid ubsan null pointer
Instead use offsetof() to determine the container pointer, otherwise
ubsan fails with "member access within null pointer".
Change-Id: I5472a1a7052fc0d6f02f2df5283eddb3be653d06
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
diff --git a/container_of.h b/container_of.h
index 2abb332..0bf1ed0 100644
--- a/container_of.h
+++ b/container_of.h
@@ -3,7 +3,7 @@
#ifndef container_of
#define container_of(ptr, type, member) \
- (type *)((char *)(ptr) - (char *)&((type *)0)->member)
+ (type *)((char *)(ptr) - offsetof(type, member))
#endif
#endif