LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Vasily Averin <vvs@virtuozzo.com>
To: linux-ext4@vger.kernel.org, Theodore Ts'o <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
	linux-kernel@vger.kernel.org,
	Yongqiang Yang <xiaoqiangnk@gmail.com>,
	Yongqiang Yang <yangyongqiang01@baidu.com>
Subject: [PATCH v2 01/11] ext4 resise: extra brelse in setup_new_flex_group_blocks()
Date: Wed, 31 Oct 2018 00:57:37 +0300	[thread overview]
Message-ID: <37de5906-2d76-461a-ff92-b6fcc775b408@virtuozzo.com> (raw)
In-Reply-To: <cover.1540935522.git.vvs@virtuozzo.com>

currently bh is set to NULL only during first iteration of for cycle,
then this pointer is not cleared after end of using.
Therefore rollback after errors can lead to extra brelse(bh) call,
decrements bh counter and later trigger an unexpected warning in __brelse()

Patch moves brelse() calls in body of cycle to exclude requirement of
brelse() call in rollback.

Fixes 33afdcc5402d ("ext4: add a function which sets up group blocks ...") # 3.3+

Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
 fs/ext4/resize.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index ebbc663d0798..c3fa30878ca8 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -605,7 +605,6 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
 		bh = bclean(handle, sb, block);
 		if (IS_ERR(bh)) {
 			err = PTR_ERR(bh);
-			bh = NULL;
 			goto out;
 		}
 		overhead = ext4_group_overhead_blocks(sb, group);
@@ -618,9 +617,9 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
 		ext4_mark_bitmap_end(EXT4_B2C(sbi, group_data[i].blocks_count),
 				     sb->s_blocksize * 8, bh->b_data);
 		err = ext4_handle_dirty_metadata(handle, NULL, bh);
+		brelse(bh);
 		if (err)
 			goto out;
-		brelse(bh);
 
 handle_ib:
 		if (bg_flags[i] & EXT4_BG_INODE_UNINIT)
@@ -635,18 +634,16 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
 		bh = bclean(handle, sb, block);
 		if (IS_ERR(bh)) {
 			err = PTR_ERR(bh);
-			bh = NULL;
 			goto out;
 		}
 
 		ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb),
 				     sb->s_blocksize * 8, bh->b_data);
 		err = ext4_handle_dirty_metadata(handle, NULL, bh);
+		brelse(bh);
 		if (err)
 			goto out;
-		brelse(bh);
 	}
-	bh = NULL;
 
 	/* Mark group tables in block bitmap */
 	for (j = 0; j < GROUP_TABLE_COUNT; j++) {
@@ -685,7 +682,6 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
 	}
 
 out:
-	brelse(bh);
 	err2 = ext4_journal_stop(handle);
 	if (err2 && !err)
 		err = err2;
-- 
2.17.1


       reply	other threads:[~2018-10-30 21:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1540935522.git.vvs@virtuozzo.com>
2018-10-30 21:57 ` Vasily Averin [this message]
2018-11-03 20:20   ` Theodore Y. Ts'o
2018-10-30 21:57 ` [PATCH v2 02/11] ext4 resize: missing brelse() after errors in set_flexbg_block_bitmap() Vasily Averin
2018-11-03 20:28   ` Theodore Y. Ts'o
2018-10-30 21:57 ` [PATCH v2 03/11] ext4 resize: brelse() cleanup in add_new_gdb_meta_bg() Vasily Averin
2018-11-03 20:55   ` Theodore Y. Ts'o
2018-10-30 21:58 ` [PATCH v2 04/11] ext4 resize: lost brelse() in update_backups() Vasily Averin
2018-11-03 21:14   ` Theodore Y. Ts'o
2018-10-30 21:58 ` [PATCH v2 05/11] ext4 resize: lost rollback in ext4_resize_fs() Vasily Averin
2018-11-06 21:17   ` Theodore Y. Ts'o
2018-10-30 21:58 ` [PATCH v2 06/11] ext4 resize: lost resize_inode cleanup before retry " Vasily Averin
2018-11-06 21:23   ` Theodore Y. Ts'o
2018-10-30 21:58 ` [PATCH v2 07/11] ext4: lost put_bh in ext4_mark_iloc_dirty() Vasily Averin
2018-11-06 21:53   ` Theodore Y. Ts'o
2018-10-30 21:58 ` [PATCH v2 08/11] ext4: lost brelse in ext4_orphan_add() Vasily Averin
2018-11-06 22:04   ` Theodore Y. Ts'o
2018-10-30 21:58 ` [PATCH v2 09/11] ext4: iloc.bh cleanup in add_new_gdb() Vasily Averin
2018-11-06 22:19   ` Theodore Y. Ts'o
2018-10-30 21:58 ` [PATCH v2 10/11] ext4: remove useless brelse call in ext4_xattr_inode_update_ref() Vasily Averin
2018-11-06 22:49   ` Theodore Y. Ts'o
2018-10-30 21:58 ` [PATCH v2 11/11] ext4: access to uninitialized bh fields in ext4_xattr_set_handle() Vasily Averin
     [not found]   ` <48BA929C-9BF7-4092-BDD3-BECB64AF0599@dilger.ca>
2018-10-31  3:39     ` Vasily Averin
2018-11-01  0:42       ` Andreas Dilger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37de5906-2d76-461a-ff92-b6fcc775b408@virtuozzo.com \
    --to=vvs@virtuozzo.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=xiaoqiangnk@gmail.com \
    --cc=yangyongqiang01@baidu.com \
    --subject='Re: [PATCH v2 01/11] ext4 resise: extra brelse in setup_new_flex_group_blocks()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).