Skip to contentSkip to conversation

FAILED: patch "[PATCH] btrfs: fix incorrect return value after changing leaf in" failed to apply to 6.12-stable tree

PATCH [email protected] 1 participant 1 message Apr 7

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 316fb1b3169efb081d2db910cbbfef445afa03b9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026040718-colt-spoon-e3c4@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 316fb1b3169efb081d2db910cbbfef445afa03b9 Mon Sep 17 00:00:00 2001
From: robbieko <[email protected]>
Date: Wed, 25 Mar 2026 18:18:15 +0800
Subject: [PATCH] btrfs: fix incorrect return value after changing leaf in
lookup_extent_data_ref()

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()")
fs/btrfs/extent-tree.c +1 -1
index 85ee5c79759d..098e64106d02 100644
@@ -495,7 +495,7 @@ again:
 		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);