@@ -110,6 +110,35 @@ static struct file_system_type ext3_fs_type = {
110110#define IS_EXT3_SB (sb ) (0)
111111#endif
112112
113+ void * ext4_kvmalloc (size_t size , gfp_t flags )
114+ {
115+ void * ret ;
116+
117+ ret = kmalloc (size , flags );
118+ if (!ret )
119+ ret = __vmalloc (size , flags , PAGE_KERNEL );
120+ return ret ;
121+ }
122+
123+ void * ext4_kvzalloc (size_t size , gfp_t flags )
124+ {
125+ void * ret ;
126+
127+ ret = kmalloc (size , flags );
128+ if (!ret )
129+ ret = __vmalloc (size , flags | __GFP_ZERO , PAGE_KERNEL );
130+ return ret ;
131+ }
132+
133+ void ext4_kvfree (void * ptr )
134+ {
135+ if (is_vmalloc_addr (ptr ))
136+ vfree (ptr );
137+ else
138+ kfree (ptr );
139+
140+ }
141+
113142ext4_fsblk_t ext4_block_bitmap (struct super_block * sb ,
114143 struct ext4_group_desc * bg )
115144{
@@ -791,10 +820,7 @@ static void ext4_put_super(struct super_block *sb)
791820 for (i = 0 ; i < sbi -> s_gdb_count ; i ++ )
792821 brelse (sbi -> s_group_desc [i ]);
793822 kfree (sbi -> s_group_desc );
794- if (is_vmalloc_addr (sbi -> s_flex_groups ))
795- vfree (sbi -> s_flex_groups );
796- else
797- kfree (sbi -> s_flex_groups );
823+ ext4_kvfree (sbi -> s_flex_groups );
798824 percpu_counter_destroy (& sbi -> s_freeblocks_counter );
799825 percpu_counter_destroy (& sbi -> s_freeinodes_counter );
800826 percpu_counter_destroy (& sbi -> s_dirs_counter );
@@ -1977,15 +2003,11 @@ static int ext4_fill_flex_info(struct super_block *sb)
19772003 ((le16_to_cpu (sbi -> s_es -> s_reserved_gdt_blocks ) + 1 ) <<
19782004 EXT4_DESC_PER_BLOCK_BITS (sb ))) / groups_per_flex ;
19792005 size = flex_group_count * sizeof (struct flex_groups );
1980- sbi -> s_flex_groups = kzalloc (size , GFP_KERNEL );
2006+ sbi -> s_flex_groups = ext4_kvzalloc (size , GFP_KERNEL );
19812007 if (sbi -> s_flex_groups == NULL ) {
1982- sbi -> s_flex_groups = vzalloc (size );
1983- if (sbi -> s_flex_groups == NULL ) {
1984- ext4_msg (sb , KERN_ERR ,
1985- "not enough memory for %u flex groups" ,
1986- flex_group_count );
1987- goto failed ;
1988- }
2008+ ext4_msg (sb , KERN_ERR , "not enough memory for %u flex groups" ,
2009+ flex_group_count );
2010+ goto failed ;
19892011 }
19902012
19912013 for (i = 0 ; i < sbi -> s_groups_count ; i ++ ) {
@@ -3750,12 +3772,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
37503772 }
37513773failed_mount3 :
37523774 del_timer (& sbi -> s_err_report );
3753- if (sbi -> s_flex_groups ) {
3754- if (is_vmalloc_addr (sbi -> s_flex_groups ))
3755- vfree (sbi -> s_flex_groups );
3756- else
3757- kfree (sbi -> s_flex_groups );
3758- }
3775+ if (sbi -> s_flex_groups )
3776+ ext4_kvfree (sbi -> s_flex_groups );
37593777 percpu_counter_destroy (& sbi -> s_freeblocks_counter );
37603778 percpu_counter_destroy (& sbi -> s_freeinodes_counter );
37613779 percpu_counter_destroy (& sbi -> s_dirs_counter );
0 commit comments