From: Anand Jain <anand.jain@oracle.com>
To: dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3 6/6] btrfs: rename and optimize return variable in btrfs_find_orphan_roots
Date: Thu, 23 May 2024 22:35:23 +0800 [thread overview]
Message-ID: <0ea513f9-bfcd-4b31-91c6-810b59a8ecca@oracle.com> (raw)
In-Reply-To: <20240521175949.GS17126@twin.jikos.cz>
On 22/05/2024 01:59, David Sterba wrote:
> On Wed, May 22, 2024 at 01:10:08AM +0800, Anand Jain wrote:
>>
>>
>> On 5/21/24 23:18, David Sterba wrote:
>>> On Thu, May 16, 2024 at 07:12:15PM +0800, Anand Jain wrote:
>>>> The variable err is the actual return value of this function, and the
>>>> variable ret is a helper variable for err, which actually is not
>>>> needed and can be handled just by err, which is renamed to ret.
>>>>
>>>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>>>> ---
>>>> v3: drop ret2 as there is no need for it.
>>>> v2: n/a
>>>> fs/btrfs/root-tree.c | 32 ++++++++++++++++----------------
>>>> 1 file changed, 16 insertions(+), 16 deletions(-)
>>>>
>>>> diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
>>>> index 33962671a96c..c11b0bccf513 100644
>>>> --- a/fs/btrfs/root-tree.c
>>>> +++ b/fs/btrfs/root-tree.c
>>>> @@ -220,8 +220,7 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
>>>> struct btrfs_path *path;
>>>> struct btrfs_key key;
>>>> struct btrfs_root *root;
>>>> - int err = 0;
>>>> - int ret;
>>>> + int ret = 0;
>>>>
>>>> path = btrfs_alloc_path();
>>>> if (!path)
>>>> @@ -235,18 +234,19 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
>>>> u64 root_objectid;
>>>>
>>>> ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0);
>>>> - if (ret < 0) {
>>>> - err = ret;
>>>> + if (ret < 0)
>>>> break;
>>>> - }
>>>> + ret = 0;
>>>
>>> Should this be handled when ret > 0? This would be unexpected and
>>> probably means a corruption but simply overwriting the value does not
>>> seem right.
>>>
>>
>> Agreed.
>>
>> + if (ret > 0)
>> + ret = 0;
>>
>> is much neater.
>
> That's not what I meant. When btrfs_search_slot() returns 1 then the key
> was not found and could be inserted, path points to the slot. This is
> done in many other places, so in the orphan root lookup it should be
> also handled.
For the scenario where ret > 0 is good, we generally do varied tasks.
However, here we need to reassign ret = 0. Originally, err remained 0
and returned 0.
Or, my bad, I didn't understand which usual error handling pattern you
are referring to.
Thanks, Anand
next prev parent reply other threads:[~2024-05-23 14:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-16 11:12 [PATCH v3 0/6] part3 trivial adjustments for return variable coding style Anand Jain
2024-05-16 11:12 ` [PATCH v3 1/6] btrfs: btrfs_cleanup_fs_roots handle ret variable Anand Jain
2024-05-21 15:10 ` David Sterba
2024-05-21 17:08 ` Anand Jain
2024-05-16 11:12 ` [PATCH v3 2/6] btrfs: simplify ret in btrfs_recover_relocation Anand Jain
2024-05-16 11:12 ` [PATCH v3 3/6] btrfs: rename " Anand Jain
2024-05-16 11:12 ` [PATCH v3 4/6] btrfs: rename err " Anand Jain
2024-05-16 11:12 ` [PATCH v3 5/6] btrfs: btrfs_drop_snapshot optimize return variable Anand Jain
2024-05-16 11:12 ` [PATCH v3 6/6] btrfs: rename and optimize return variable in btrfs_find_orphan_roots Anand Jain
2024-05-21 15:18 ` David Sterba
2024-05-21 17:10 ` Anand Jain
2024-05-21 17:59 ` David Sterba
2024-05-23 14:35 ` Anand Jain [this message]
2024-05-21 1:04 ` [PATCH v3 0/6] part3 trivial adjustments for return variable coding style Anand Jain
2024-05-21 15:21 ` David Sterba
2024-05-21 17:10 ` Anand Jain
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=0ea513f9-bfcd-4b31-91c6-810b59a8ecca@oracle.com \
--to=anand.jain@oracle.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox