mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-09 07:23:14 +00:00
ext4: miscellaneous error checks and coding cleanups for mballoc
ext4_mb_seq_history_open(): check if sbi->s_mb_history is NULL ext4_mb_history_init(): replace kmalloc and memset with kzalloc ext4_mb_init_backend(): remove memset since kzalloc is used ext4_mb_init(): the return value of ext4_mb_init_backend is int, but i is unsigned, replace it with a new int variable. Signed-off-by: Shen Feng <shen@cn.fujitsu.com> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
parent
fdf6c7a768
commit
74767c5a2d
@ -1985,6 +1985,8 @@ static int ext4_mb_seq_history_open(struct inode *inode, struct file *file)
|
|||||||
int rc;
|
int rc;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
|
if (unlikely(sbi->s_mb_history == NULL))
|
||||||
|
return -ENOMEM;
|
||||||
s = kmalloc(sizeof(*s), GFP_KERNEL);
|
s = kmalloc(sizeof(*s), GFP_KERNEL);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -2187,9 +2189,7 @@ static void ext4_mb_history_init(struct super_block *sb)
|
|||||||
sbi->s_mb_history_cur = 0;
|
sbi->s_mb_history_cur = 0;
|
||||||
spin_lock_init(&sbi->s_mb_history_lock);
|
spin_lock_init(&sbi->s_mb_history_lock);
|
||||||
i = sbi->s_mb_history_max * sizeof(struct ext4_mb_history);
|
i = sbi->s_mb_history_max * sizeof(struct ext4_mb_history);
|
||||||
sbi->s_mb_history = kmalloc(i, GFP_KERNEL);
|
sbi->s_mb_history = kzalloc(i, GFP_KERNEL);
|
||||||
if (likely(sbi->s_mb_history != NULL))
|
|
||||||
memset(sbi->s_mb_history, 0, i);
|
|
||||||
/* if we can't allocate history, then we simple won't use it */
|
/* if we can't allocate history, then we simple won't use it */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2303,7 +2303,6 @@ static int ext4_mb_init_backend(struct super_block *sb)
|
|||||||
i++;
|
i++;
|
||||||
goto err_freebuddy;
|
goto err_freebuddy;
|
||||||
}
|
}
|
||||||
memset(meta_group_info[j], 0, len);
|
|
||||||
set_bit(EXT4_GROUP_INFO_NEED_INIT_BIT,
|
set_bit(EXT4_GROUP_INFO_NEED_INIT_BIT,
|
||||||
&(meta_group_info[j]->bb_state));
|
&(meta_group_info[j]->bb_state));
|
||||||
|
|
||||||
@ -2358,6 +2357,7 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
|
|||||||
unsigned i;
|
unsigned i;
|
||||||
unsigned offset;
|
unsigned offset;
|
||||||
unsigned max;
|
unsigned max;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!test_opt(sb, MBALLOC))
|
if (!test_opt(sb, MBALLOC))
|
||||||
return 0;
|
return 0;
|
||||||
@ -2392,12 +2392,12 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
|
|||||||
} while (i <= sb->s_blocksize_bits + 1);
|
} while (i <= sb->s_blocksize_bits + 1);
|
||||||
|
|
||||||
/* init file for buddy data */
|
/* init file for buddy data */
|
||||||
i = ext4_mb_init_backend(sb);
|
ret = ext4_mb_init_backend(sb);
|
||||||
if (i) {
|
if (ret != 0) {
|
||||||
clear_opt(sbi->s_mount_opt, MBALLOC);
|
clear_opt(sbi->s_mount_opt, MBALLOC);
|
||||||
kfree(sbi->s_mb_offsets);
|
kfree(sbi->s_mb_offsets);
|
||||||
kfree(sbi->s_mb_maxs);
|
kfree(sbi->s_mb_maxs);
|
||||||
return i;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_init(&sbi->s_md_lock);
|
spin_lock_init(&sbi->s_md_lock);
|
||||||
|
Loading…
Reference in New Issue
Block a user