]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] ext2_fill_super breakage
authorAndrew Morton <akpm@zip.com.au>
Tue, 2 Apr 2002 03:44:16 +0000 (19:44 -0800)
committerLinus Torvalds <torvalds@home.transmeta.com>
Tue, 2 Apr 2002 03:44:16 +0000 (19:44 -0800)
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.

fs/autofs/inode.c
fs/devpts/inode.c
fs/ext2/super.c

index cc9c70c158fe29016085513e810fb240a07747a4..e2e3dcb8e7a997cd15fc39dafbaffecf76bfb8c9 100644 (file)
@@ -119,9 +119,10 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
        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;
index 742a42d8a519dea7bd5ad6674c41c788112af754..ce8f545fb8a59d66ba6c961ffb01dd32efdde331 100644 (file)
@@ -123,9 +123,10 @@ static int devpts_fill_super(struct super_block *s, void *data, int silent)
        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;
index c11c360401672151c6e59104aa977accaa3bfc8a..e3f8ec62c1cb84888ae824a33d52e0ba29d4dff9 100644 (file)
@@ -465,11 +465,11 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
        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