[PATCH v2 08/20] Implement container_of_safe() in terms of container_of()

From: Alejandro Colomar
Date: Sat Nov 20 2021 - 08:01:36 EST


There's no more a need for the temporary variable __mptr,
since now it's only passed to functions that accept a 'const void *',
and everything can convert automatically to it,
reducing the need for the cast too.

Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
---
include/linux/container_of.h | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 220990db7b61..03809348f333 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -30,12 +30,7 @@
*
* If IS_ERR_OR_NULL(ptr), ptr is returned unchanged.
*/
-#define container_of_safe(ptr, type, member) ({ \
- void *__mptr = (void *)(ptr); \
- static_assert(__same_type(*(ptr), ((type *)0)->member) || \
- __same_type(*(ptr), void), \
- "pointer type mismatch in container_of_safe()"); \
- IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) : \
- ((type *)(__mptr - offsetof(type, member))); })
+#define container_of_safe(ptr, type, member) \
+ (IS_ERR_OR_NULL(ptr) ? ERR_CAST(ptr) : container_of(type, member))

#endif /* _LINUX_CONTAINER_OF_H */
--
2.33.1