Re: [PATCH 4.19 166/422] f2fs: fix memory leak of percpu counter in fill_super()

From: Pavel Machek
Date: Thu Nov 21 2019 - 08:39:23 EST


Hi!

> From: Chao Yu <yuchao0@xxxxxxxxxx>
>
> [ Upstream commit 4a70e255449c9a13eed7a6eeecc85a1ea63cef76 ]
>
> In fill_super -> init_percpu_info, we should destroy percpu counter
> in error path, otherwise memory allcoated for percpu counter will
> leak.

> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 58931d55dc1d2..c5d28e92d146e 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -2516,8 +2516,12 @@ static int init_percpu_info(struct f2fs_sb_info *sbi)
> if (err)
> return err;
>
> - return percpu_counter_init(&sbi->total_valid_inode_count, 0,
> + err = percpu_counter_init(&sbi->total_valid_inode_count, 0,
> GFP_KERNEL);
> + if (err)
> + percpu_counter_destroy(&sbi->alloc_valid_block_count);
> +
> + return err;
> }

Are you sure this is good idea? Normally when _init() fails, the thing
is not allocated, and there is nothing to destroy...

If you are right, there's same bug in fs/xfs/xfs_buf.c .

Best regards,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Attachment: signature.asc
Description: PGP signature