[PATCH v3 1/6] btrfs: use an on-stack path in btrfs_insert_orphan_item()

From: Jeff Layton

Date: Tue Aug 11 2026 - 14:15:47 EST


btrfs_insert_orphan_item() allocated a btrfs_path with btrfs_alloc_path()
which returns -ENOMEM on failure. It is called from btrfs_orphan_add(),
so a path allocation failure there turns a recoverable error into a
transaction abort.

btrfs_path is only ~112 bytes, so allocate it on the stack instead.

Assisted-by: LLM
Suggested-by: Qu Wenruo <wqu@xxxxxxxx>
Reviewed-by: Qu Wenruo <wqu@xxxxxxxx>
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
fs/btrfs/orphan.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/orphan.c b/fs/btrfs/orphan.c
index 9f3ad124104f..72e1adec39d8 100644
--- a/fs/btrfs/orphan.c
+++ b/fs/btrfs/orphan.c
@@ -9,18 +9,17 @@
int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 offset)
{
- BTRFS_PATH_AUTO_FREE(path);
+ struct btrfs_path path = { 0 };
struct btrfs_key key;
+ int ret;

key.objectid = BTRFS_ORPHAN_OBJECTID;
key.type = BTRFS_ORPHAN_ITEM_KEY;
key.offset = offset;

- path = btrfs_alloc_path();
- if (!path)
- return -ENOMEM;
-
- return btrfs_insert_empty_item(trans, root, path, &key, 0);
+ ret = btrfs_insert_empty_item(trans, root, &path, &key, 0);
+ btrfs_release_path(&path);
+ return ret;
}

int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,

--
2.55.0