From: Pekka J Enberg <penberg@cs.Helsinki.FI>
To: Russell King <rmk+lkml@arm.linux.org.uk>
Cc: Linux Kernel List <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@osdl.org>,
Al Viro <viro@ftp.linux.org.uk>, Andrew Morton <akpm@osdl.org>
Subject: Re: p = kmalloc(sizeof(*p), )
Date: Tue, 20 Sep 2005 15:20:18 +0300 (EEST) [thread overview]
Message-ID: <Pine.LNX.4.58.0509201501440.9304@sbz-30.cs.Helsinki.FI> (raw)
In-Reply-To: <20050920114003.GA31025@flint.arm.linux.org.uk>
Hi Russell,
On Tue, 20 Sep 2005, Russell King wrote:
> Think about it some more. You've added a new member to struct foo.
> You want to fix up all the places which allocate struct foo to
> initialise this new member. Grepping for 'struct foo' returns 100
> files. Grepping for kmalloc in those 100 files returns 100 files.
>
> Do you open all 100 in an editor and manually try and locate the five
> kmalloc instances of this structure, and end up missing some.
Nope. I grep for assignments to other members of that struct.
On Tue, 20 Sep 2005, Russell King wrote:
> Or do you do the sane thing and use kmalloc(sizeof(struct foo), ...)
> and grep for "kmalloc[[:space:]]*(sizeof[[:space:]]*(struct foo)"
> which returns only the five files and fix those up with knowledge
> that you've found all the instances?
There are still statically allocated structs left. So neither heuristic
for figuring out initialization points is perfect.
On 9/18/05, Russell King <rmk+lkml@arm.linux.org.uk> wrote:
> Such shuffling around should be done in easy to review stages so that
> bugs can be found, and not a mega patch. This inherently means that
> for a structure name change, you don't end up with a new structure
> named the same as an old structure. And if you compile-test the
> stages, you find out if you missed the problem.
No disagreement here.
On 9/18/05, Russell King <rmk+lkml@arm.linux.org.uk> wrote:
> Your solution is better if the only thing you're concerned about is
> "are we allocating enough memory for this fixed size structure".
> It completely breaks if you are also concerned about "are we doing
> correct initialisation" or "are we allocating enough memory for this
> variable sized structure" both of which are far more important
> questions.
>
> *especially* when you consider that kmalloc is redzoned and therefore
> will catch the kinds of bugs you're suggesting.
Well, yes, but for initialization, I would prefer something like what Al
Viro suggested. To me, initialization is a separate issue from kmalloc. I
do get your point but I just don't think sizeof(struct foo) is the answer.
In all completeness, I would personally prefer the following form for
allocation and initialization which is readable, easy to get right, and
highly greppable:
struct foo *p = kmalloc(sizeof *p, ...);
*p = (struct foo) {
.bar = ...;
};
Unfortunately it doesn't seem like gcc is doing such a good job with it.
Pekka
next prev parent reply other threads:[~2005-09-20 12:20 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-18 10:06 p = kmalloc(sizeof(*p), ) Russell King
2005-09-18 11:04 ` Alan Cox
2005-09-18 14:39 ` Al Viro
2005-09-18 16:25 ` Denis Vlasenko
2005-09-18 17:30 ` Al Viro
2005-09-18 18:00 ` Willy Tarreau
2005-09-18 17:47 ` Alan Cox
2005-09-18 16:32 ` Robert Love
2005-09-18 16:52 ` Willy Tarreau
2005-09-18 17:18 ` Al Viro
2005-09-18 17:31 ` Linus Torvalds
2005-09-18 17:45 ` Al Viro
2005-09-18 20:34 ` Roman Zippel
2005-09-18 21:12 ` Al Viro
2005-09-18 21:52 ` Al Viro
2005-09-18 22:25 ` Linus Torvalds
2005-09-18 23:07 ` Al Viro
2005-09-20 6:31 ` Richard Henderson
2005-09-19 21:20 ` Matthias Urlichs
2005-09-19 21:28 ` Matthias Urlichs
2005-09-18 19:07 ` Al Viro
2005-09-18 21:30 ` Alan Cox
2005-09-18 21:14 ` Al Viro
2005-09-19 6:09 ` Coywolf Qi Hunt
2005-09-21 2:18 ` Miles Bader
2005-09-18 17:32 ` Randy.Dunlap
2005-09-19 6:47 ` Coywolf Qi Hunt
2005-09-20 8:53 ` Pekka Enberg
2005-09-20 9:39 ` Al Viro
2005-09-20 9:47 ` Pekka J Enberg
2005-09-20 9:53 ` Al Viro
2005-09-20 10:07 ` Pekka J Enberg
2005-09-20 15:14 ` Randy.Dunlap
2005-09-20 11:18 ` Pekka Enberg
2005-09-20 11:40 ` Russell King
2005-09-20 11:56 ` Denis Vlasenko
2005-09-20 12:20 ` Pekka J Enberg [this message]
2005-09-20 12:31 ` Russell King
2005-09-20 12:35 ` Pekka J Enberg
2005-09-20 15:21 ` Randy.Dunlap
2005-09-20 12:53 ` Pekka J Enberg
2005-09-20 17:11 ` Andrew Morton
2005-09-20 17:17 ` Russell King
2005-09-20 18:02 ` Alan Cox
2005-09-20 17:59 ` Andrew Morton
2005-09-20 18:11 ` Russell King
2005-09-20 18:41 ` Jeff Garzik
2005-09-20 20:41 ` Alan Cox
2005-09-20 19:41 ` Horst von Brand
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=Pine.LNX.4.58.0509201501440.9304@sbz-30.cs.Helsinki.FI \
--to=penberg@cs.helsinki.fi \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rmk+lkml@arm.linux.org.uk \
--cc=torvalds@osdl.org \
--cc=viro@ftp.linux.org.uk \
/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).