[PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf

Kemeng Shi posted 7 patches 1 year, 6 months ago
There is a newer version of this series
[PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf
Posted by Kemeng Shi 1 year, 6 months ago
Simply return -EINVAL if j_fc_off is invalid to avoid repeated check of
ret.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/jbd2/journal.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index dc18b9f7c999..6f90f7b8e9e5 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -842,12 +842,8 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
 		fc_off = journal->j_fc_off;
 		blocknr = journal->j_fc_first + fc_off;
 		journal->j_fc_off++;
-	} else {
-		ret = -EINVAL;
-	}
-
-	if (ret)
-		return ret;
+	} else
+		return -EINVAL;
 
 	ret = jbd2_journal_bmap(journal, blocknr, &pblock);
 	if (ret)
-- 
2.30.0
Re: [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf
Posted by Zhang Yi 1 year, 6 months ago
On 2024/7/30 19:33, Kemeng Shi wrote:
> Simply return -EINVAL if j_fc_off is invalid to avoid repeated check of
> ret.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
>  fs/jbd2/journal.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index dc18b9f7c999..6f90f7b8e9e5 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -842,12 +842,8 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
>  		fc_off = journal->j_fc_off;
>  		blocknr = journal->j_fc_first + fc_off;
>  		journal->j_fc_off++;
> -	} else {
> -		ret = -EINVAL;
> -	}
> -
> -	if (ret)
> -		return ret;
> +	} else
> +		return -EINVAL;
>  

I'd like this style, just a suggestion.

	if (journal->j_fc_off + journal->j_fc_first >= journal->j_fc_last)
		return -EINVAL;

	fc_off = journal->j_fc_off;
	blocknr = journal->j_fc_first + fc_off;
	journal->j_fc_off++;

	...

Thanks,
Yi.


>  	ret = jbd2_journal_bmap(journal, blocknr, &pblock);
>  	if (ret)
>
Re: [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf
Posted by Kemeng Shi 1 year, 6 months ago

on 7/31/2024 2:17 PM, Zhang Yi wrote:
> On 2024/7/30 19:33, Kemeng Shi wrote:
>> Simply return -EINVAL if j_fc_off is invalid to avoid repeated check of
>> ret.
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
>> ---
>>  fs/jbd2/journal.c | 8 ++------
>>  1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
>> index dc18b9f7c999..6f90f7b8e9e5 100644
>> --- a/fs/jbd2/journal.c
>> +++ b/fs/jbd2/journal.c
>> @@ -842,12 +842,8 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
>>  		fc_off = journal->j_fc_off;
>>  		blocknr = journal->j_fc_first + fc_off;
>>  		journal->j_fc_off++;
>> -	} else {
>> -		ret = -EINVAL;
>> -	}
>> -
>> -	if (ret)
>> -		return ret;
>> +	} else
>> +		return -EINVAL;
>>  
> 
> I'd like this style, just a suggestion.
> 
> 	if (journal->j_fc_off + journal->j_fc_first >= journal->j_fc_last)
> 		return -EINVAL;
> 
> 	fc_off = journal->j_fc_off;
> 	blocknr = journal->j_fc_first + fc_off;
> 	journal->j_fc_off++;
> 
> 	...
> 
Sorry, I miss this. I also think code looks better in this way. I will do
it in next version. Thanks.
> Thanks,
> Yi.
> 
> 
>>  	ret = jbd2_journal_bmap(journal, blocknr, &pblock);
>>  	if (ret)
>>
>
Re: [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf
Posted by Jan Kara 1 year, 6 months ago
On Tue 30-07-24 19:33:35, Kemeng Shi wrote:
> Simply return -EINVAL if j_fc_off is invalid to avoid repeated check of
> ret.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/jbd2/journal.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index dc18b9f7c999..6f90f7b8e9e5 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -842,12 +842,8 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
>  		fc_off = journal->j_fc_off;
>  		blocknr = journal->j_fc_first + fc_off;
>  		journal->j_fc_off++;
> -	} else {
> -		ret = -EINVAL;
> -	}
> -
> -	if (ret)
> -		return ret;
> +	} else
> +		return -EINVAL;
>  
>  	ret = jbd2_journal_bmap(journal, blocknr, &pblock);
>  	if (ret)
> -- 
> 2.30.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR