From: Catalin Marinas <catalin.marinas@arm.com>
To: Tejun Heo <htejun@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Use a zero-size array in the struct devres
Date: Tue, 06 Mar 2007 15:21:33 +0000 [thread overview]
Message-ID: <tnx1wk2mm82.fsf@arm.com> (raw)
In-Reply-To: <45ED818F.2030502@gmail.com> (Tejun Heo's message of "Tue, 06 Mar 2007 23:58:23 +0900")
Tejun Heo <htejun@gmail.com> wrote:
> Catalin Marinas wrote:
>> It sounds to me like the alignment of an incomplete type is not
>> guaranteed (as you can't even enquire about it, though I might be
>> wrong). This is probably dependent on the compiler as well - with
>> gcc-3.3 on x86, __alignof__(unsigned long long) is 8 but the
>> "offsetof(struct test, data)" below is 12 (and it doesn't make any
>> difference whether it is a 0-size array or not):
>>
>> struct test {
>> unsigned long a;
>> unsigned long b;
>> unsigned long c;
>> unsigned long long data[];
>> };
>
> data[0] and data[1] or whatever will also give you offset of 12. Dunno
> why, but it is. Anyways, whatever the wording in the manual is,
> flexible arrays just have to have the required alignment to do its job
> as advertised. :-)
On ARM (with gcc-4) it gives 16 for both offsetof and sizeof.
>> I did a quick grep through the kernel and it looks like Linux mainly
>> uses 0-size rather than flexible arrays at the end of a structure
>> (>500 vs ~14). This might be for historical reasons but it's not a big
>> issue in modifying them.
>
> I think it's mostly historical. Flexible array is still a relatively
> new thing. I don't mind changing devres to zero sized array, but please
> explain in the commit message and as a comment that the choice is for
> kmemleak's container_of(), and cc Greg K-H as the change should probably
> go through his tree.
OK. I'll probably wait until I post a new version of kmemleak against
2.6.21-rcX.
Thanks.
--
Catalin
prev parent reply other threads:[~2007-03-06 15:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-06 9:54 [PATCH] Use a zero-size array in the struct devres Catalin Marinas
2007-03-06 12:44 ` Tejun Heo
2007-03-06 14:40 ` Catalin Marinas
2007-03-06 14:58 ` Tejun Heo
2007-03-06 15:21 ` Catalin Marinas [this message]
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=tnx1wk2mm82.fsf@arm.com \
--to=catalin.marinas@arm.com \
--cc=htejun@gmail.com \
--cc=linux-kernel@vger.kernel.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