lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 19 Nov 2021 12:36:38 +0100
From:   Alejandro Colomar <alx.manpages@...il.com>
To:     LKML <linux-kernel@...r.kernel.org>
Cc:     Alejandro Colomar <alx.manpages@...il.com>
Subject: [PATCH 10/17] linux/container_of.h: Implement container_of_safe() in terms of container_of()

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@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ