Re: [patch] ext2_fill_super breakage

From: Andrew Morton (akpm@zip.com.au)
Date: Thu Mar 28 2002 - 12:45:18 EST


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
 
 /*

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



This archive was generated by hypermail 2b29 : Sun Mar 31 2002 - 22:00:16 EST