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] [day] [month] [year] [list]
Date:	Thu, 16 Apr 2009 19:33:27 +0100
From:	Al Viro <viro@...IV.linux.org.uk>
To:	H Hartley Sweeten <hartleys@...ionengravers.com>
Cc:	Vegard Nossum <vegard.nossum@...il.com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] block/genhd.c: fix sparse warning

On Thu, Apr 16, 2009 at 02:03:39PM -0400, H Hartley Sweeten wrote:

> Maybe something like:
> 
> 	#define container_of(ptr, type, member) ({			\
> 		const typeof( ((type *)0)->member ) *__m_##ptr = (ptr);	\
> 		(type *)( (char *)__m_##ptr - offsetof(type,member) );})
> 
> I don't know if that actually works. ;-)

_Think_ of it.  Will do bleeding wonders if you say
	container_of(f(), struct foo, bar)
won't it?

No, the real solution for that is this:
#define container_of(ptr, type, member) (type *)	\
	((char *)(1 ? (ptr) : ((const typeof(((type *)0)->member) *)(ptr))) \
         - offsetof(type, member))
Same amount of typechecking, no local variables, no ({ }) uses.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ