saction(trans, ret);
}
```

**3. Adds ASSERT** for transaction handle validation in the wc->pin path

### Why Backport:

1. **Part of coordinated error handling improvements**: This is commit
   2/4 in a series (preceded by 6ebd726b104fa on same day, followed by
   commits 77ea42e3faa1f, 97b027586a189, and ultimately 2753e49176240
   which enhances all these aborts with detailed debugging)

2. **Slightly improves error handling**: While errors were eventually
   handled, this ensures transaction aborts happen closer to the failure
   point, potentially preventing additional operations on a doomed
   transaction

3. **Minimal risk**: The changes only add error handling paths without
   modifying core logic

4. **Already selected by AUTOSEL**: Commit exists as 5650f88050dd5 with
   backport tag, indicating it passed automated selection criteria

5. **Well-reviewed**: Has reviews from Boris Burkov, Qu Wenruo, and
   David Sterba

6. **Confined scope**: Changes limited to process_one_buffer() in tree-
   log.c

### Caveats:

- **No "Fixes:" tag**: Author did not tag this as fixing a specific bug
- **No "Cc: stable" tag**: Author did not explicitly request stable
  backport
- **Primary benefit is debugging**: The main value is better error
  diagnosis rather than fixing user-visible issues
- **Part of larger series**: Functions best with the full series of log
  replay improvements

**Verdict**: YES - This is a quality improvement that enhances error
handling with minimal risk. While borderline as it's primarily for
debugging, the slight functional improvement to error handling and
AUTOSEL selection support backporting to stable trees.

 fs/btrfs/tree-log.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 6d92326a1a0c7..50ed84cb68a69 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -347,6 +347,7 @@ static int process_one_buffer(struct btrfs_root *log,
 			      struct extent_buffer *eb,
 			      struct walk_control *wc, u64 gen, int level)
 {
+	struct btrfs_trans_handle *trans = wc->trans;
 	struct btrfs_fs_info *fs_info = log->fs_info;
 	int ret = 0;
 
@@ -361,18 +362,29 @@ static int process_one_buffer(struct btrfs_root *log,
 		};
 
 		ret = btrfs_read_extent_buffer(eb, &check);
-		if (ret)
+		if (ret) {
+			if (trans)
+				btrfs_abort_transaction(trans, ret);
+			else
+				btrfs_handle_fs_error(fs_info, ret, NULL);
 			return ret;
+		}
 	}
 
 	if (wc->pin) {
-		ret = btrfs_pin_extent_for_log_replay(wc->trans, eb);
-		if (ret)
+		ASSERT(trans != NULL);
+		ret = btrfs_pin_extent_for_log_replay(trans, eb);
+		if (ret) {
+			btrfs_abort_transaction(trans, ret);
 			return ret;
+		}
 
 		if (btrfs_buffer_uptodate(eb, gen, 0) &&
-		    btrfs_header_level(eb) == 0)
+		    btrfs_header_level(eb) == 0) {
 			ret = btrfs_exclude_logged_extents(eb);
+			if (ret)
+				btrfs_abort_transaction(trans, ret);
+		}
 	}
 	return ret;
 }
-- 
2.51.0[PATCH AUTOSEL 6.17-6.12] btrfs: abort transaction in the process_one_buffer() log tree walk callbackSasha Levin <sashal@kernel.org> undefinedpatches@lists.linux.dev, stable@vger.kernel.org undefined undefined undefined undefined undefined undefined undefined undefined