public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] ext2_fill_super breakage
@ 2002-03-28  7:30 Andrew Morton
  2002-03-28 13:34 ` Brian Gerst
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Andrew Morton @ 2002-03-28  7:30 UTC (permalink / raw)
  To: lkml, Linus Torvalds

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));

I checked the other filesystems.  They're OK (but idiomatically
impure).  I've added a couple of defensive memsets where
they were missing.


--- 2.5.7/fs/autofs/inode.c~fill-super	Wed Mar 27 23:14:20 2002
+++ 2.5.7-akpm/fs/autofs/inode.c	Wed Mar 27 23:14:54 2002
@@ -119,9 +119,10 @@ int autofs_fill_super(struct super_block
 	struct autofs_sb_info *sbi;
 	int minproto, maxproto;
 
-	sbi = (struct autofs_sb_info *) kmalloc(sizeof(struct autofs_sb_info), GFP_KERNEL);
+	sbi = kmalloc(sizeof(*sbi), GFP_KERNEL);
 	if ( !sbi )
 		goto fail_unlock;
+	memset(sbi, 0, sizeof(*sbi));
 	DPRINTK(("autofs: starting up, sbi = %p\n",sbi));
 
 	s->u.generic_sbp = sbi;
--- 2.5.7/fs/devpts/inode.c~fill-super	Wed Mar 27 23:16:05 2002
+++ 2.5.7-akpm/fs/devpts/inode.c	Wed Mar 27 23:16:33 2002
@@ -123,9 +123,10 @@ static int devpts_fill_super(struct supe
 	struct inode * inode;
 	struct devpts_sb_info *sbi;
 
-	sbi = (struct devpts_sb_info *) kmalloc(sizeof(struct devpts_sb_info), GFP_KERNEL);
+	sbi = kmalloc(sizeof(*sbi), GFP_KERNEL);
 	if ( !sbi )
 		goto fail;
+	memset(sbi, 0, sizeof(*sbi));
 
 	sbi->magic  = DEVPTS_SBI_MAGIC;
 	sbi->max_ptys = unix98_max_ptys;
--- 2.5.7/fs/ext2/super.c~fill-super	Wed Mar 27 23:16:57 2002
+++ 2.5.7-akpm/fs/ext2/super.c	Wed Mar 27 23:17:25 2002
@@ -465,11 +465,11 @@ static int ext2_fill_super(struct super_
 	int db_count;
 	int i, j;
 
-	sbi = kmalloc(sizeof(struct ext2_super_block), GFP_KERNEL);
+	sbi = kmalloc(sizeof(*sbi), GFP_KERNEL);
 	if (!sbi)
 		return -ENOMEM;
 	sb->u.generic_sbp = sbi;
-	memset(sbi, 0, sizeof(struct ext2_super_block));
+	memset(sbi, 0, sizeof(*sbi));
 
 	/*
 	 * See what the current blocksize for the device is, and


-

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2002-03-29 15:48 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox