Skip to content

Commit 0b6d4ca

Browse files
ebiggersJaegeuk Kim
authored andcommitted
f2fs: don't return vmalloc() memory from f2fs_kmalloc()
kmalloc() returns kmalloc'ed memory, and kvmalloc() returns either kmalloc'ed or vmalloc'ed memory. But the f2fs wrappers, f2fs_kmalloc() and f2fs_kvmalloc(), both return both kinds of memory. It's redundant to have two functions that do the same thing, and also breaking the standard naming convention is causing bugs since people assume it's safe to kfree() memory allocated by f2fs_kmalloc(). See e.g. the various allocations in fs/f2fs/compress.c. Fix this by making f2fs_kmalloc() just use kmalloc(). And to avoid re-introducing the allocation failures that the vmalloc fallback was intended to fix, convert the largest allocations to use f2fs_kvmalloc(). Signed-off-by: Eric Biggers <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent e78790f commit 0b6d4ca

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

fs/f2fs/checkpoint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,8 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
895895
int i;
896896
int err;
897897

898-
sbi->ckpt = f2fs_kzalloc(sbi, array_size(blk_size, cp_blks),
899-
GFP_KERNEL);
898+
sbi->ckpt = f2fs_kvzalloc(sbi, array_size(blk_size, cp_blks),
899+
GFP_KERNEL);
900900
if (!sbi->ckpt)
901901
return -ENOMEM;
902902
/*

fs/f2fs/f2fs.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,18 +2997,12 @@ static inline bool f2fs_may_extent_tree(struct inode *inode)
29972997
static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
29982998
size_t size, gfp_t flags)
29992999
{
3000-
void *ret;
3001-
30023000
if (time_to_inject(sbi, FAULT_KMALLOC)) {
30033001
f2fs_show_injection_info(sbi, FAULT_KMALLOC);
30043002
return NULL;
30053003
}
30063004

3007-
ret = kmalloc(size, flags);
3008-
if (ret)
3009-
return ret;
3010-
3011-
return kvmalloc(size, flags);
3005+
return kmalloc(size, flags);
30123006
}
30133007

30143008
static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,

fs/f2fs/node.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,7 +2993,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
29932993
return 0;
29942994

29952995
nm_i->nat_bits_blocks = F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8);
2996-
nm_i->nat_bits = f2fs_kzalloc(sbi,
2996+
nm_i->nat_bits = f2fs_kvzalloc(sbi,
29972997
nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, GFP_KERNEL);
29982998
if (!nm_i->nat_bits)
29992999
return -ENOMEM;
@@ -3126,9 +3126,9 @@ static int init_free_nid_cache(struct f2fs_sb_info *sbi)
31263126
int i;
31273127

31283128
nm_i->free_nid_bitmap =
3129-
f2fs_kzalloc(sbi, array_size(sizeof(unsigned char *),
3130-
nm_i->nat_blocks),
3131-
GFP_KERNEL);
3129+
f2fs_kvzalloc(sbi, array_size(sizeof(unsigned char *),
3130+
nm_i->nat_blocks),
3131+
GFP_KERNEL);
31323132
if (!nm_i->free_nid_bitmap)
31333133
return -ENOMEM;
31343134

fs/f2fs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,7 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
30333033
if (nr_sectors & (bdev_zone_sectors(bdev) - 1))
30343034
FDEV(devi).nr_blkz++;
30353035

3036-
FDEV(devi).blkz_seq = f2fs_kzalloc(sbi,
3036+
FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi,
30373037
BITS_TO_LONGS(FDEV(devi).nr_blkz)
30383038
* sizeof(unsigned long),
30393039
GFP_KERNEL);

0 commit comments

Comments
 (0)