From: Ian Abbott <abbotti@mev.co.uk>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Michal Nazarewicz <mina86@mina86.com>,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>,
Borislav Petkov <bp@suse.de>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Johannes Berg <johannes.berg@intel.com>,
Alexander Potapenko <glider@google.com>
Subject: Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()
Date: Tue, 23 May 2017 13:02:59 +0100 [thread overview]
Message-ID: <ec5747cf-0222-42eb-91fa-e67c4c0f3f61@mev.co.uk> (raw)
In-Reply-To: <20170523112415.nmbazvqmlhy343f2@hirez.programming.kicks-ass.net>
On 23/05/17 12:24, Peter Zijlstra wrote:
> On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote:
>
>>> #define container_of(ptr, type, member) ( \
>>> _Static_assert(__builtin_types_compatible_p( \
>>> typeof(*ptr), typeof( ((type *)0)->member )), "WUT"), \
>>> ((type *)((char *)(ptr) - offsetof(type, member))); \
>>> )
>>
>> It's a fine suggestion (if more parentheses are added), but _Static_assert
>> is a C11 feature, and I thought the kernel was using gnu89 (unless it's been
>> updated since).
>
> We have BUILD_BUG_ON() that should be similar in functionality.
Yes, I think BUILD_BUG_ON_ZERO() will be better in this case to avoid
some baggage. Also, __same_type() can be used for type checking.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@mev.co.uk> )=-
-=( Web: http://www.mev.co.uk/ )=-
next prev parent reply other threads:[~2017-05-23 12:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-22 15:03 Ian Abbott
2017-05-22 17:58 ` Michal Nazarewicz
2017-05-23 10:32 ` Ian Abbott
2017-05-23 11:24 ` Peter Zijlstra
2017-05-23 12:02 ` Ian Abbott [this message]
2017-05-23 13:23 ` Ian Abbott
2017-05-23 14:14 ` Ian Abbott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ec5747cf-0222-42eb-91fa-e67c4c0f3f61@mev.co.uk \
--to=abbotti@mev.co.uk \
--cc=akpm@linux-foundation.org \
--cc=bp@suse.de \
--cc=glider@google.com \
--cc=hidehiro.kawai.ez@hitachi.com \
--cc=johannes.berg@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mina86@mina86.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®