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>] [day] [month] [year] [list]
Message-ID: <918ffad0-20d9-40cb-8dd5-ee082752d463@p183>
Date: Fri, 19 Jul 2024 22:08:37 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: akpm@...ux-foundation.org
Cc: linux-kernel@...r.kernel.org, andriy.shevchenko@...ux.intel.com
Subject: [PATCH] simplify container_of()

* delete unnecessary variable,
* delete unnecessary parenthesis.

This changes generated code for some reason :-\

	add/remove: 6/0 grow/shrink: 26/42 up/down: 1945/-1591 (354)
	Function                                     old     new   delta
	ip_route_output_ports                          -     724    +724
		...
	udp_lib_setsockopt                          2785    2291    -494
	Total: Before=83970531, After=83970885, chg +0.00%

But it shouldn't: cast is unnecessary and static_assert() doesn't
generate code. Variable "__mptr" is ised only in one place.
offsetof() is evaluated at compile time.

It is not clear what's going on.

Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
---

 include/linux/container_of.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -16,11 +16,11 @@
  * WARNING: any const qualifier of @ptr is lost.
  */
 #define container_of(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()");	\
-	((type *)(__mptr - offsetof(type, member))); })
+	(type *)((void *)(ptr) - offsetof(type, member));		\
+})
 
 /**
  * container_of_const - cast a member of a structure out to the containing

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ