[PATCH v3 2/6] btrfs: use an on-stack path in btrfs_del_orphan_item()
From: Jeff Layton
Date: Tue Aug 11 2026 - 14:15:41 EST
btrfs_del_orphan_item() allocated a btrfs_path with btrfs_alloc_path()
which returns -ENOMEM on failure. It is called from btrfs_orphan_del(),
and btrfs_link() turns any error from it into a transaction abort. So a
path allocation failure there (reachable via linkat() on an O_TMPFILE
under memory pressure) turns a recoverable error into an abort.
btrfs_path is only ~112 bytes, so allocate it on the stack instead.
Unlike the insert case there are multiple exit points after the search,
so release the path via a common out: label.
Assisted-by: LLM
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
fs/btrfs/orphan.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/fs/btrfs/orphan.c b/fs/btrfs/orphan.c
index 72e1adec39d8..ae1685f26dec 100644
--- a/fs/btrfs/orphan.c
+++ b/fs/btrfs/orphan.c
@@ -25,23 +25,24 @@ int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
int btrfs_del_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 = 0;
+ int ret;
key.objectid = BTRFS_ORPHAN_OBJECTID;
key.type = BTRFS_ORPHAN_ITEM_KEY;
key.offset = offset;
- path = btrfs_alloc_path();
- if (!path)
- return -ENOMEM;
-
- ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
+ ret = btrfs_search_slot(trans, root, &key, &path, -1, 1);
if (ret < 0)
- return ret;
- if (ret)
- return -ENOENT;
-
- return btrfs_del_item(trans, root, path);
+ goto out;
+ if (ret) {
+ ret = -ENOENT;
+ goto out;
+ }
+
+ ret = btrfs_del_item(trans, root, &path);
+out:
+ btrfs_release_path(&path);
+ return ret;
}
--
2.55.0