[PATCH 1/6] ext4: add missing brelse for bh2 in ext4_dx_add_entry

Kemeng Shi posted 6 patches 12 months ago
There is a newer version of this series
[PATCH 1/6] ext4: add missing brelse for bh2 in ext4_dx_add_entry
Posted by Kemeng Shi 12 months ago
Add missing brelse for bh2 in ext4_dx_add_entry.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/ext4/namei.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 1012781ae9b4..adec145b6f7d 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -2580,8 +2580,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
 		BUFFER_TRACE(frame->bh, "get_write_access");
 		err = ext4_journal_get_write_access(handle, sb, frame->bh,
 						    EXT4_JTR_NONE);
-		if (err)
+		if (err) {
+			brelse(bh2);
 			goto journal_error;
+		}
 		if (!add_level) {
 			unsigned icount1 = icount/2, icount2 = icount - icount1;
 			unsigned hash2 = dx_get_hash(entries + icount1);
@@ -2592,8 +2594,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
 			err = ext4_journal_get_write_access(handle, sb,
 							    (frame - 1)->bh,
 							    EXT4_JTR_NONE);
-			if (err)
+			if (err) {
+				brelse(bh2);
 				goto journal_error;
+			}
 
 			memcpy((char *) entries2, (char *) (entries + icount1),
 			       icount2 * sizeof(struct dx_entry));
@@ -2612,8 +2616,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
 			dxtrace(dx_show_index("node",
 			       ((struct dx_node *) bh2->b_data)->entries));
 			err = ext4_handle_dirty_dx_node(handle, dir, bh2);
-			if (err)
+			if (err) {
+				brelse(bh2);
 				goto journal_error;
+			}
 			brelse (bh2);
 			err = ext4_handle_dirty_dx_node(handle, dir,
 						   (frame - 1)->bh);
@@ -2638,8 +2644,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
 				       "Creating %d level index...\n",
 				       dxroot->info.indirect_levels));
 			err = ext4_handle_dirty_dx_node(handle, dir, frame->bh);
-			if (err)
+			if (err) {
+				brelse(bh2);
 				goto journal_error;
+			}
 			err = ext4_handle_dirty_dx_node(handle, dir, bh2);
 			brelse(bh2);
 			restart = 1;
-- 
2.30.0
Re: [PATCH 1/6] ext4: add missing brelse for bh2 in ext4_dx_add_entry
Posted by Zhang Yi 12 months ago
On 2024/12/19 19:00, Kemeng Shi wrote:
> Add missing brelse for bh2 in ext4_dx_add_entry.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>

It's a good catch, looks good to me.

Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

> ---
>  fs/ext4/namei.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 1012781ae9b4..adec145b6f7d 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -2580,8 +2580,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  		BUFFER_TRACE(frame->bh, "get_write_access");
>  		err = ext4_journal_get_write_access(handle, sb, frame->bh,
>  						    EXT4_JTR_NONE);
> -		if (err)
> +		if (err) {
> +			brelse(bh2);
>  			goto journal_error;
> +		}
>  		if (!add_level) {
>  			unsigned icount1 = icount/2, icount2 = icount - icount1;
>  			unsigned hash2 = dx_get_hash(entries + icount1);
> @@ -2592,8 +2594,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  			err = ext4_journal_get_write_access(handle, sb,
>  							    (frame - 1)->bh,
>  							    EXT4_JTR_NONE);
> -			if (err)
> +			if (err) {
> +				brelse(bh2);
>  				goto journal_error;
> +			}
>  
>  			memcpy((char *) entries2, (char *) (entries + icount1),
>  			       icount2 * sizeof(struct dx_entry));
> @@ -2612,8 +2616,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  			dxtrace(dx_show_index("node",
>  			       ((struct dx_node *) bh2->b_data)->entries));
>  			err = ext4_handle_dirty_dx_node(handle, dir, bh2);
> -			if (err)
> +			if (err) {
> +				brelse(bh2);
>  				goto journal_error;
> +			}
>  			brelse (bh2);
>  			err = ext4_handle_dirty_dx_node(handle, dir,
>  						   (frame - 1)->bh);
> @@ -2638,8 +2644,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  				       "Creating %d level index...\n",
>  				       dxroot->info.indirect_levels));
>  			err = ext4_handle_dirty_dx_node(handle, dir, frame->bh);
> -			if (err)
> +			if (err) {
> +				brelse(bh2);
>  				goto journal_error;
> +			}
>  			err = ext4_handle_dirty_dx_node(handle, dir, bh2);
>  			brelse(bh2);
>  			restart = 1;
Re: [PATCH 1/6] ext4: add missing brelse for bh2 in ext4_dx_add_entry
Posted by Markus Elfring 12 months ago
> Add missing brelse for bh2 in ext4_dx_add_entry.

* I propose to append parentheses to function names.

* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13-rc3#n145


…
> +++ b/fs/ext4/namei.c
> @@ -2580,8 +2580,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  		BUFFER_TRACE(frame->bh, "get_write_access");
>  		err = ext4_journal_get_write_access(handle, sb, frame->bh,
>  						    EXT4_JTR_NONE);
> -		if (err)
> +		if (err) {
> +			brelse(bh2);
>  			goto journal_error;
> +		}
>  		if (!add_level) {
…

I suggest to add another jump target instead so that a bit of exception handling
can be better reused at the end of this function implementation.

Regards,
Markus
Re: [PATCH 1/6] ext4: add missing brelse for bh2 in ext4_dx_add_entry
Posted by Kemeng Shi 11 months, 4 weeks ago

on 12/20/2024 9:15 PM, Markus Elfring wrote:
>> Add missing brelse for bh2 in ext4_dx_add_entry.
> 
> * I propose to append parentheses to function names.
> 
> * How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
>   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13-rc3#n145
Sure, will handle these in next version.

Thanks,
Kemeng
> 
> 
> …
>> +++ b/fs/ext4/namei.c
>> @@ -2580,8 +2580,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>>  		BUFFER_TRACE(frame->bh, "get_write_access");
>>  		err = ext4_journal_get_write_access(handle, sb, frame->bh,
>>  						    EXT4_JTR_NONE);
>> -		if (err)
>> +		if (err) {
>> +			brelse(bh2);
>>  			goto journal_error;
>> +		}
>>  		if (!add_level) {
> …
> 
> I suggest to add another jump target instead so that a bit of exception handling
> can be better reused at the end of this function implementation.
> 
> Regards,
> Markus
> 

Re: [PATCH 1/6] ext4: add missing brelse for bh2 in ext4_dx_add_entry
Posted by Ojaswin Mujoo 12 months ago
On Thu, Dec 19, 2024 at 07:00:22PM +0800, Kemeng Shi wrote:
> Add missing brelse for bh2 in ext4_dx_add_entry.

Looks good, feel free to add:

Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

Regards,
ojaswin

> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
>  fs/ext4/namei.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 1012781ae9b4..adec145b6f7d 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -2580,8 +2580,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  		BUFFER_TRACE(frame->bh, "get_write_access");
>  		err = ext4_journal_get_write_access(handle, sb, frame->bh,
>  						    EXT4_JTR_NONE);
> -		if (err)
> +		if (err) {
> +			brelse(bh2);
>  			goto journal_error;
> +		}
>  		if (!add_level) {
>  			unsigned icount1 = icount/2, icount2 = icount - icount1;
>  			unsigned hash2 = dx_get_hash(entries + icount1);
> @@ -2592,8 +2594,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  			err = ext4_journal_get_write_access(handle, sb,
>  							    (frame - 1)->bh,
>  							    EXT4_JTR_NONE);
> -			if (err)
> +			if (err) {
> +				brelse(bh2);
>  				goto journal_error;
> +			}
>  
>  			memcpy((char *) entries2, (char *) (entries + icount1),
>  			       icount2 * sizeof(struct dx_entry));
> @@ -2612,8 +2616,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  			dxtrace(dx_show_index("node",
>  			       ((struct dx_node *) bh2->b_data)->entries));
>  			err = ext4_handle_dirty_dx_node(handle, dir, bh2);
> -			if (err)
> +			if (err) {
> +				brelse(bh2);
>  				goto journal_error;
> +			}
>  			brelse (bh2);
>  			err = ext4_handle_dirty_dx_node(handle, dir,
>  						   (frame - 1)->bh);
> @@ -2638,8 +2644,10 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  				       "Creating %d level index...\n",
>  				       dxroot->info.indirect_levels));
>  			err = ext4_handle_dirty_dx_node(handle, dir, frame->bh);
> -			if (err)
> +			if (err) {
> +				brelse(bh2);
>  				goto journal_error;
> +			}
>  			err = ext4_handle_dirty_dx_node(handle, dir, bh2);
>  			brelse(bh2);
>  			restart = 1;
> -- 
> 2.30.0
>