public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Filipe Manana <fdmanana@kernel.org>
To: robbieko <robbieko@synology.com>
Cc: fstests@vger.kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: fix incorrect return value after crossing leaf boundary in lookup_extent_data_ref
Date: Wed, 25 Mar 2026 18:22:25 +0000	[thread overview]
Message-ID: <CAL3q7H71wE3L14DHYUZ+2cAK-GSd3aU5iY4qypXAdfNNyf9_WA@mail.gmail.com> (raw)
In-Reply-To: <20260325101818.3474340-1-robbieko@synology.com>

On Wed, Mar 25, 2026 at 10:28 AM robbieko <robbieko@synology.com> wrote:
>
> After commit 1618aa3c2e01 ("btrfs: simplify return variables in
> lookup_extent_data_ref()"), the err and ret variables were merged into
> a single ret variable. However, when btrfs_next_leaf() returns 0
> (success), ret is overwritten from -ENOENT to 0. If the first key in
> the next leaf does not match (different objectid or type), the function
> returns 0 instead of -ENOENT, making the caller believe the lookup
> succeeded when it did not. This can lead to operations on the wrong
> extent tree item, potentially causing extent tree corruption.
>
> Fix this by returning -ENOENT directly when the key does not match,
> instead of relying on the ret variable.
>
> Fixes: 1618aa3c2e01 ("btrfs: simplify return variables in lookup_extent_data_ref()")
> Signed-off-by: robbieko <robbieko@synology.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Looks good, thanks.

> ---
>  fs/btrfs/extent-tree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 85ee5c79759d..098e64106d02 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -495,7 +495,7 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
>                 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
>                 if (key.objectid != bytenr ||
>                     key.type != BTRFS_EXTENT_DATA_REF_KEY)
> -                       return ret;
> +                       return -ENOENT;
>
>                 ref = btrfs_item_ptr(leaf, path->slots[0],
>                                      struct btrfs_extent_data_ref);
> --
> 2.43.0
>
>
> Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.
>

      reply	other threads:[~2026-03-25 18:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-25 10:18 [PATCH] btrfs: fix incorrect return value after crossing leaf boundary in lookup_extent_data_ref robbieko
2026-03-25 18:22 ` Filipe Manana [this message]

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=CAL3q7H71wE3L14DHYUZ+2cAK-GSd3aU5iY4qypXAdfNNyf9_WA@mail.gmail.com \
    --to=fdmanana@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=robbieko@synology.com \
    /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