lkml.org 
[lkml]   [2021]   [Nov]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 10/17] linux/container_of.h: Implement container_of_safe() in terms of container_of()
Date
Avoid duplicate code.  There's only one different statement.  Let it be so.

Note: I'm not sure if we really need a void pointer for IS_ERR_OR_NULL(),
or we could remove that line altogether.

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
---
include/linux/container_of.h | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 45aa73f5e392..addd3993fa60 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -30,12 +30,13 @@
*
* If IS_ERR_OR_NULL(ptr), ptr is returned unchanged.
*/
-#define container_of_safe(ptr, type, member) ({ \
+#define container_of_safe(ptr, type, member) ( \
+{ \
void *__mptr = (void *)(ptr); \
- static_assert(__same_type(*(ptr), memberof(type, 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))); })
+ container_of(ptr, type, member); \
+} \
+)

#endif /* _LINUX_CONTAINER_OF_H */
--
2.33.1
\
 
 \ /
  Last update: 2021-11-19 12:39    [W:0.407 / U:0.152 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site