2019-10-22 09:19:21

by Chengguang Xu

[permalink] [raw]
Subject: [PATCH v2] ext2: add missing brelse in ext2_new_blocks()

There is a missing brelse of bitmap_bh in the
case of retry.

Signed-off-by: Chengguang Xu <[email protected]>
---
v1->v2:
- Add comment to explain why the fix is needed.

fs/ext2/balloc.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 924c1c765306..18e75adcd2f6 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -1313,6 +1313,13 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
if (free_blocks > 0) {
grp_target_blk = ((goal - le32_to_cpu(es->s_first_data_block)) %
EXT2_BLOCKS_PER_GROUP(sb));
+ /*
+ * In a special case that allocated blocks are in system zone,
+ * we will retry block allocation due to failing to pass sanity
+ * check. In this case, the bitmap_bh is non-null pointer and we
+ * have to release it before calling read_block_bitmap().
+ */
+ brelse(bitmap_bh);
bitmap_bh = read_block_bitmap(sb, group_no);
if (!bitmap_bh)
goto io_error;
--
2.20.1




2019-10-22 09:27:39

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH v2] ext2: add missing brelse in ext2_new_blocks()

On Tue 22-10-19 17:17:38, Chengguang Xu wrote:
> There is a missing brelse of bitmap_bh in the
> case of retry.
>
> Signed-off-by: Chengguang Xu <[email protected]>

Thanks. Patch applied with small update to the comment - this can also hit
in case our reservation window was alredy full.

Honza

> ---
> v1->v2:
> - Add comment to explain why the fix is needed.
>
> fs/ext2/balloc.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
> index 924c1c765306..18e75adcd2f6 100644
> --- a/fs/ext2/balloc.c
> +++ b/fs/ext2/balloc.c
> @@ -1313,6 +1313,13 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
> if (free_blocks > 0) {
> grp_target_blk = ((goal - le32_to_cpu(es->s_first_data_block)) %
> EXT2_BLOCKS_PER_GROUP(sb));
> + /*
> + * In a special case that allocated blocks are in system zone,
> + * we will retry block allocation due to failing to pass sanity
> + * check. In this case, the bitmap_bh is non-null pointer and we
> + * have to release it before calling read_block_bitmap().
> + */
> + brelse(bitmap_bh);
> bitmap_bh = read_block_bitmap(sb, group_no);
> if (!bitmap_bh)
> goto io_error;
> --
> 2.20.1
>
>
>
--
Jan Kara <[email protected]>
SUSE Labs, CR