Skip to contentSkip to conversation

ext3: fix ext34_fill_super group description initialization

PATCH In review Dmitry Monakhov 4 participants 4 messages Aug 13, 2007 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext3: fix ext34_fill_super group description initialization

->s_group_desc have to be zero filled because if sb_read() failed we jump to following error path.
failed_mount2:

	for (i = 0; i < db_count; i++)
		brelse(sbi->s_group_desc[i]);<< Bad things may happen here
---
 fs/ext3/super.c |    2 +-
 fs/ext4/super.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/ext3/super.c +1 -1
index f8ac18f..208738e 100644
@@ -1718,7 +1718,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
 				       / EXT3_BLOCKS_PER_GROUP(sb)) + 1;
 	db_count = (sbi->s_groups_count + EXT3_DESC_PER_BLOCK(sb) - 1) /
 		   EXT3_DESC_PER_BLOCK(sb);
-	sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
+	sbi->s_group_desc = kzalloc(db_count * sizeof (struct buffer_head *),
 				    GFP_KERNEL);
 	if (sbi->s_group_desc == NULL) {
 		printk (KERN_ERR "EXT3-fs: not enough memory\n");
fs/ext4/super.c +1 -1
index 8f1d2f6..fefffc0 100644
@@ -1830,7 +1830,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)
 	sbi->s_groups_count = blocks_count;
 	db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
 		   EXT4_DESC_PER_BLOCK(sb);
-	sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
+	sbi->s_group_desc = kzalloc(db_count * sizeof (struct buffer_head *),
 				    GFP_KERNEL);
 	if (sbi->s_group_desc == NULL) {
 		printk (KERN_ERR "EXT4-fs: not enough memory\n");
Signature · 1 line
1.5.2.2
#1 lore raw
Quoted 5 lines · Dmitry Monakhov

->s_group_desc have to be zero filled because if sb_read() failed we jump to following error path.
failed_mount2:

	for (i = 0; i < db_count; i++)
		brelse(sbi->s_group_desc[i]);<< Bad things may happen here

OOPs i'm sorry. I've lost db_count changing after sb_read() error, so error path is ok, and this patch is not needed.

Quoted 41 lines
---
 fs/ext3/super.c |    2 +-
 fs/ext4/super.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/ext3/super.c +1 -1
index f8ac18f..208738e 100644
@@ -1718,7 +1718,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
 				       / EXT3_BLOCKS_PER_GROUP(sb)) + 1;
 	db_count = (sbi->s_groups_count + EXT3_DESC_PER_BLOCK(sb) - 1) /
 		   EXT3_DESC_PER_BLOCK(sb);
-	sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
+	sbi->s_group_desc = kzalloc(db_count * sizeof (struct buffer_head *),
 				    GFP_KERNEL);
 	if (sbi->s_group_desc == NULL) {
 		printk (KERN_ERR "EXT3-fs: not enough memory\n");
fs/ext4/super.c +1 -1
index 8f1d2f6..fefffc0 100644
@@ -1830,7 +1830,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)
 	sbi->s_groups_count = blocks_count;
 	db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
 		   EXT4_DESC_PER_BLOCK(sb);
-	sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
+	sbi->s_group_desc = kzalloc(db_count * sizeof (struct buffer_head *),
 				    GFP_KERNEL);
 	if (sbi->s_group_desc == NULL) {
 		printk (KERN_ERR "EXT4-fs: not enough memory\n");
Signature · 7 lines
1.5.2.2


-
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to Dmitry Monakhov
Quoted 6 lines · Dmitry Monakhov

->s_group_desc have to be zero filled because if sb_read() failed we jump to following error path.
failed_mount2:

	for (i = 0; i < db_count; i++)
		brelse(sbi->s_group_desc[i]);<< Bad things may happen here

But the db_count is updated in the failure path to point to the number of successful sb_read.

-aneesh

#3 lore raw
In reply to Dmitry Monakhov
Quoted 17 lines

->s_group_desc have to be zero filled because if sb_read() failed we jump to following error path.
failed_mount2:

	for (i = 0; i < db_count; i++)
		brelse(sbi->s_group_desc[i]);<< Bad things may happen here
---
 fs/ext3/super.c |    2 +-
 fs/ext4/super.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/ext3/super.c +0 -0
index f8ac18f..208738e 100644

fs/ext3/super.c static int ext3_fill_super (struct super_block *sb, · line 1722

Quoted 6 lines
fs/ext3/super.c +1 -1
@@ -1718,7 +1718,7 @@ static int ext3_fill_super (struct super_block *sb,
 void *data, int silent) / EXT3_BLOCKS_PER_GROUP(sb)) + 1;
 	db_count = (sbi->s_groups_count + EXT3_DESC_PER_BLOCK(sb) - 1) /
 		   EXT3_DESC_PER_BLOCK(sb);
-	sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
+	sbi->s_group_desc = kzalloc(db_count * sizeof (struct buffer_head *),
 				    GFP_KERNEL);

kcalloc?

fs/ext4/super.c static int ext4_fill_super (struct super_block *sb, · line 1834

Quoted 13 lines
fs/ext3/super.c +0 -0
 	if (sbi->s_group_desc == NULL) {
 		printk (KERN_ERR "EXT3-fs: not enough memory\n");
fs/ext4/super.c +1 -1
index 8f1d2f6..fefffc0 100644
@@ -1830,7 +1830,7 @@ static int ext4_fill_super (struct super_block *sb,
 void *data, int silent) sbi->s_groups_count = blocks_count;
 	db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
 		   EXT4_DESC_PER_BLOCK(sb);
-	sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
+	sbi->s_group_desc = kzalloc(db_count * sizeof (struct buffer_head *),
 				    GFP_KERNEL);

kcalloc?

fs/ext4/super.c static int ext4_fill_super (struct super_block *sb, void *data, int silent) · line 1836

Quoted 2 lines
fs/ext4/super.c +0 -0
 	if (sbi->s_group_desc == NULL) {
 		printk (KERN_ERR "EXT4-fs: not enough memory\n");

Regards,

Mariusz