diff mbox series

[v3,08/19] ext4: get block from bh before pass it to ext4_free_blocks_simple in ext4_free_blocks

Message ID 20230417110617.2664129-9-shikemeng@huaweicloud.com
State Superseded
Headers show
Series Fixes, cleanups and unit test for mballoc | expand

Commit Message

Kemeng Shi April 17, 2023, 11:06 a.m. UTC
ext4_free_blocks will retrieve block from bh if block parameter is zero.
Retrieve block before ext4_free_blocks_simple to avoid potentially
passing wrong block to ext4_free_blocks_simple.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/ext4/mballoc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Ojaswin Mujoo May 12, 2023, 6:29 a.m. UTC | #1
On Mon, Apr 17, 2023 at 07:06:06PM +0800, Kemeng Shi wrote:
> ext4_free_blocks will retrieve block from bh if block parameter is zero.
> Retrieve block before ext4_free_blocks_simple to avoid potentially
> passing wrong block to ext4_free_blocks_simple.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Hi Kemeng,

Nice catch! feel free to add:

Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> ---
>  fs/ext4/mballoc.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index e980513c7a14..f37e921c11e5 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -6310,12 +6310,6 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
>  
>  	sbi = EXT4_SB(sb);
>  
> -	if (sbi->s_mount_state & EXT4_FC_REPLAY) {
> -		ext4_free_blocks_simple(inode, block, count);
> -		return;
> -	}
> -
> -	might_sleep();
>  	if (bh) {
>  		if (block)
>  			BUG_ON(block != bh->b_blocknr);
> @@ -6323,6 +6317,13 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
>  			block = bh->b_blocknr;
>  	}
>  
> +	if (sbi->s_mount_state & EXT4_FC_REPLAY) {
> +		ext4_free_blocks_simple(inode, block, count);
> +		return;
> +	}
> +
> +	might_sleep();
> +
>  	if (!(flags & EXT4_FREE_BLOCKS_VALIDATED) &&
>  	    !ext4_inode_block_valid(inode, block, count)) {
>  		ext4_error(sb, "Freeing blocks not in datazone - "
> -- 
> 2.30.0
>
diff mbox series

Patch

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index e980513c7a14..f37e921c11e5 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -6310,12 +6310,6 @@  void ext4_free_blocks(handle_t *handle, struct inode *inode,
 
 	sbi = EXT4_SB(sb);
 
-	if (sbi->s_mount_state & EXT4_FC_REPLAY) {
-		ext4_free_blocks_simple(inode, block, count);
-		return;
-	}
-
-	might_sleep();
 	if (bh) {
 		if (block)
 			BUG_ON(block != bh->b_blocknr);
@@ -6323,6 +6317,13 @@  void ext4_free_blocks(handle_t *handle, struct inode *inode,
 			block = bh->b_blocknr;
 	}
 
+	if (sbi->s_mount_state & EXT4_FC_REPLAY) {
+		ext4_free_blocks_simple(inode, block, count);
+		return;
+	}
+
+	might_sleep();
+
 	if (!(flags & EXT4_FREE_BLOCKS_VALIDATED) &&
 	    !ext4_inode_block_valid(inode, block, count)) {
 		ext4_error(sb, "Freeing blocks not in datazone - "