From: Denis Vlasenko <vda@ilport.com.ua>
To: Al Viro <viro@ftp.linux.org.uk>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
Russell King <rmk+lkml@arm.linux.org.uk>,
Linux Kernel List <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@osdl.org>
Subject: Re: p = kmalloc(sizeof(*p), )
Date: Sun, 18 Sep 2005 19:25:24 +0300 [thread overview]
Message-ID: <200509181925.25112.vda@ilport.com.ua> (raw)
In-Reply-To: <20050918143907.GK19626@ftp.linux.org.uk>
On Sunday 18 September 2005 17:39, Al Viro wrote:
> On Sun, Sep 18, 2005 at 12:04:34PM +0100, Alan Cox wrote:
>
> > Other good practice in many cases is a single routine which allocates
> > and initialises the structure and is used by all allocators of that
> > object. That removes duplicate initialisers, stops people forgetting to
> > update all cases, allows better debug and far more.
>
> Indeed. IMO, argument for sizeof(*p) is bullshit - "I've changed a pointer
> type and forgot to update the allocation and initialization, but this will
> magically save my arse" is missing "except that initialization will remain
> bogus" part.
>
> I've seen a lot of bugs around bogus kmalloc+initialization, but I can't
> recall a single case when such bug would be prevented by using that form.
> If somebody has a different experience, please post pointers to changesets
> in question.
Do these qualify?
http://www.uwsg.iu.edu/hypermail/linux/kernel/0105.1/0579.html
o Fix wrong kmalloc sizes in ixj/emu10k1 (David Chan)
http://www.mail-archive.com/alsa-cvslog@lists.sourceforge.net/msg02483.html
Update of /cvsroot/alsa/alsa-kernel/isa
In directory sc8-pr-cvs1:/tmp/cvs-serv4034
Modified Files:
es18xx.c cmi8330.c
Log Message:
Fixed wrong kmalloc
After looking at output of grep -r -C10 'malloc.*sizeof' .
(epic picture) I think that maybe Alan's typechecking kmalloc
would be useful:
On Sunday 18 September 2005 14:04, Alan Cox wrote:
> If it bugs people add a kmalloc_object macro that is
>
> #define new_object(foo, gfp) (foo *)kmalloc(sizeof(foo), (gfp))
>
> then you can
>
> x = new_object(struct frob, GFP_KERNEL)
This will emit a warning if x is not a struct frob*,
which plain kmalloc doesn't do.
--
vda
next prev parent reply other threads:[~2005-09-18 16:26 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 [this message]
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
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=200509181925.25112.vda@ilport.com.ua \
--to=vda@ilport.com.ua \
--cc=alan@lxorguk.ukuu.org.uk \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.