From: Tejun Heo <htejun@gmail.com>
To: "zhao, forrest" <forrest.zhao@intel.com>
Cc: Jeff Garzik <jgarzik@pobox.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Albert Lee <albertcc@tw.ibm.com>, Jens Axboe <axboe@suse.de>,
Edward Falk <efalk@google.com>,
Carlos Pardo <Carlos.Pardo@siliconimage.com>,
Raymond Liu <Raymond.Liu@siliconimage.com>,
"linux-ide@vger.kernel.org" <linux-ide@vger.kernel.org>
Subject: Re: [ANNOUNCE] libata EH/NCQ/hotplug/PM git tree
Date: Thu, 11 May 2006 16:07:40 +0900 [thread overview]
Message-ID: <4462E2BC.5070808@gmail.com> (raw)
In-Reply-To: <1147316967.7273.26.camel@forrest26.sh.intel.com>
Hi, Zhao.
zhao, forrest wrote:
> On Wed, 2006-05-10 at 10:44 +0900, Tejun Heo wrote:
>> Hello, all.
> Tejun,
>
> I have comments about definition of macro ata_link_for_each_dev(dev,
> link) and struct ata_port{};.
>
> In the definition of struct ata_port{}, there's
> ......
> struct ata_link link;
> struct ata_device __dev1;
> ......
>
> Then macro ata_link_for_each_dev() assumes that the field 'device' in
> struct ata_link is adjacent to field '__dev1' in struct ata_port.
>
> I think this assumption is not correct in theory. Because the alignment
> may make these two fields not adjacent in memory.
>
> Although we haven't found the problem so far, it's very dangerous to
> have such assumption in the code.
Well, I think the technique is pretty widespread w/ flexible array
member, which is C99 standard and before C99 GCC had zero length array
for the same purpose. e.g.
struct asdf {
int nr_entries;
void *ar[];
};
struct asdf *p;
p = kmalloc(sizeof(*p) + nr * sizeof(p->ar[0], GFP_KERNEL);
if (p)
p->nr_entries = nr;
This works because alignof(outer struct) >= alignof(nested struct). So,
we might end up allocating a few extra bytes due to alignment
requirements but that's perfectly okay.
__dev1 is the same. It might or might not be allocated right after
link->dev[0] but it's guaranteed that &link->dev[1] <= &link->__dev1.
So, no problem there. I'm pretty sure that this kind of technique is
used in other parts of the kernel too.
--
tejun
next prev parent reply other threads:[~2006-05-11 7:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-10 1:44 [ANNOUNCE] libata EH/NCQ/hotplug/PM git tree Tejun Heo
2006-05-10 4:51 ` zhao, forrest
2006-05-10 5:17 ` Tejun Heo
2006-05-10 5:36 ` zhao, forrest
2006-05-10 6:29 ` Raz Ben-Jehuda(caro)
2006-05-10 6:33 ` Tejun Heo
2006-05-10 13:37 ` Shem Multinymous
2006-05-10 16:44 ` Shem Multinymous
2006-05-11 3:09 ` zhao, forrest
2006-05-11 7:07 ` Tejun Heo [this message]
2006-05-13 1:30 ` Jeff Garzik
2006-05-13 1:36 ` Tejun Heo
2006-05-13 3:37 ` Jeff Garzik
2006-05-13 3:59 ` Tejun Heo
2006-05-13 4:09 ` Jeff Garzik
2006-05-13 4:19 ` Tejun Heo
2006-05-13 10:02 ` Stefan Smietanowski
2006-05-13 10:20 ` Tejun Heo
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=4462E2BC.5070808@gmail.com \
--to=htejun@gmail.com \
--cc=Carlos.Pardo@siliconimage.com \
--cc=Raymond.Liu@siliconimage.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=albertcc@tw.ibm.com \
--cc=axboe@suse.de \
--cc=efalk@google.com \
--cc=forrest.zhao@intel.com \
--cc=jgarzik@pobox.com \
--cc=linux-ide@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;
as well as URLs for NNTP newsgroup(s).