Commit 7048ea4d authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] ext2_fill_super breakage

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.
parent 5be8243b
...@@ -119,9 +119,10 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) ...@@ -119,9 +119,10 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
struct autofs_sb_info *sbi; struct autofs_sb_info *sbi;
int minproto, maxproto; int minproto, maxproto;
sbi = (struct autofs_sb_info *) kmalloc(sizeof(struct autofs_sb_info), GFP_KERNEL); sbi = kmalloc(sizeof(*sbi), GFP_KERNEL);
if ( !sbi ) if ( !sbi )
goto fail_unlock; goto fail_unlock;
memset(sbi, 0, sizeof(*sbi));
DPRINTK(("autofs: starting up, sbi = %p\n",sbi)); DPRINTK(("autofs: starting up, sbi = %p\n",sbi));
s->u.generic_sbp = sbi; s->u.generic_sbp = sbi;
......
...@@ -123,9 +123,10 @@ static int devpts_fill_super(struct super_block *s, void *data, int silent) ...@@ -123,9 +123,10 @@ static int devpts_fill_super(struct super_block *s, void *data, int silent)
struct inode * inode; struct inode * inode;
struct devpts_sb_info *sbi; 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 ) if ( !sbi )
goto fail; goto fail;
memset(sbi, 0, sizeof(*sbi));
sbi->magic = DEVPTS_SBI_MAGIC; sbi->magic = DEVPTS_SBI_MAGIC;
sbi->max_ptys = unix98_max_ptys; sbi->max_ptys = unix98_max_ptys;
......
...@@ -465,11 +465,11 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) ...@@ -465,11 +465,11 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
int db_count; int db_count;
int i, j; int i, j;
sbi = kmalloc(sizeof(struct ext2_super_block), GFP_KERNEL); sbi = kmalloc(sizeof(*sbi), GFP_KERNEL);
if (!sbi) if (!sbi)
return -ENOMEM; return -ENOMEM;
sb->u.generic_sbp = sbi; 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 * See what the current blocksize for the device is, and
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment