Re: p = kmalloc(sizeof(*p), )

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Sun, 18 Sep 2005, Al Viro wrote:

> > On Sun, 18 Sep 2005, Al Viro wrote:
> > > 
> > > That's why you do
> > > 	*p = (struct foo){....};
> > > instead of
> > > 	memset(p, 0, sizeof...);
> > > 	p->... =...;
> > 
> > Actually, some day that migth be a good idea, but at least historically, 
> > gcc has really really messed that kind of code up.
> > 
> > Last I looked, depending on what the initializer was, gcc would create a 
> > temporary struct on the stack first, and then do a "memcpy()" of the 
> > result. Not only does that obviously generate a lot of extra code, it also 
> > blows your kernel stack to kingdom come.
> 
> Ewwwww...  I'd say that it qualifies as one hell of a bug (and yes, at least
> 3.3 and 4.0.1 are still doing that).  What a mess...

It's not a bug, it's exactly what you're asking for, e.g. "*p1 = *p2" 
translates to memcpy. gcc also can't simply initialize that structure in 
place, e.g. you could do something like this (not necessarily useful but 
still valid): "*p = (struct foo){...,  bar(p),...};".
In the end it all depends on how good gcc can optimize away the memcpy, 
but initially there is always a memcpy.

bye, Roman
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux