public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@zip.com.au>
To: Alexander Viro <viro@math.psu.edu>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@transmeta.com>
Subject: Re: [patch] ext2_fill_super breakage
Date: Thu, 28 Mar 2002 09:45:18 -0800	[thread overview]
Message-ID: <3CA356AE.2E61F712@zip.com.au> (raw)
In-Reply-To: <3CA2C68E.5B8C4176@zip.com.au> <Pine.GSO.4.21.0203280918190.24447-100000@weyl.math.psu.edu>

Alexander Viro wrote:
> 
> On Wed, 27 Mar 2002, Andrew Morton wrote:
> 
> > In 2.5.7 there is a thinko in the allocation and initialisation
> > of the fs-private superblock for ext2.  It's passing the wrong type
> > to the sizeof operator (which of course gives the wrong size)
> > when allocating and clearing the memory.
> 
> > Lesson for the day: this is one of the reasons why this idiom:
> >
> >       some_type *p;
> >
> >       p = malloc(sizeof(*p));
> >       ...
> >       memset(p, 0, sizeof(*p));
> >
> > is preferable to
> >
> >       some_type *p;
> >
> >       p = malloc(sizeof(some_type));
> >       ...
> >       memset(p, 0, sizeof(some_type));
> 
> ... however, there is a lot of reasons why the former is preferable.

Yeah, a lot of newbies think that :)

> For one thing, the latter is hell on any search.

If the usage of the type is hard to search for then
then wrong identifier was chosen.

>  Moreover, I would
> argue that memset() on a structure is not a good idea - better do
> the explicit initialization.

memset will run at up to twice the speed (according to
Arjan).  Dunno if this includes I-cache misses - probably
not.

I'm not particularly fussed about this one, but I do prefer
the sleep-at-night safety of a blanket memset.  Because
(and I think this is something on which you and I somewhat
differ) code should be written for the convenience of others,
not the original author.  A nice memset will leave no doubt
in the reader's mind that all members of the structure have
been initialised.

BTW, Linus: while we're on the topic, I think we should do
this again:

--- linux-2.5.7/mm/slab.c	Sat Mar  9 00:18:43 2002
+++ 25/mm/slab.c	Thu Mar 28 09:42:41 2002
@@ -95,9 +95,9 @@
 #define	STATS		1
 #define	FORCED_DEBUG	1
 #else
-#define	DEBUG		0
-#define	STATS		0
-#define	FORCED_DEBUG	0
+#define	DEBUG		1	/* It's a development kernel */
+#define	STATS		1
+#define	FORCED_DEBUG	1
 #endif
 
 /*

-

  parent reply	other threads:[~2002-03-28 17:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-28  7:30 [patch] ext2_fill_super breakage Andrew Morton
2002-03-28 13:34 ` Brian Gerst
2002-03-28 13:46   ` Rob Landley
2002-03-28 13:50   ` Jos Hulzink
2002-03-28 17:26   ` Bill Davidsen
2002-03-28 17:27   ` Andrew Morton
2002-03-28 18:13     ` Brian Gerst
2002-03-28 14:21 ` Alexander Viro
2002-03-28 14:36   ` Nikita Danilov
2002-03-28 14:48     ` Alexander Viro
2002-03-28 14:51       ` Nikita Danilov
2002-03-28 15:20         ` Alexander Viro
2002-03-28 14:50     ` Arjan van de Ven
2002-03-28 15:01       ` Nikita Danilov
2002-03-28 17:45   ` Andrew Morton [this message]
2002-03-28 23:51     ` Alexander Viro
2002-03-29  0:25       ` Andrew Morton
2002-03-29  5:14         ` Andreas Dilger
2002-03-29  8:06         ` Guest section DW
2002-03-29 15:45         ` Bill Davidsen
2002-03-29  0:42     ` Bill Davidsen
2002-03-28 22:45 ` Brian Gerst

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=3CA356AE.2E61F712@zip.com.au \
    --to=akpm@zip.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    --cc=viro@math.psu.edu \
    /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