Re: [PATCH v2 1/5] btrfs: use an on-stack path in btrfs_insert_orphan_item()

Qu Wenruo <[email protected]>
Newsgroups org.kernel.vger.linux-btrfs,org.kernel.vger.linux-kernel
Message-ID <[email protected]>

在 2026/8/5 01:14, Jeff Layton 写道:
> 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 <[email protected]>
> Signed-off-by: Jeff Layton <[email protected]>

Reviewed-by: Qu Wenruo <[email protected]>

Thanks,
Qu

> ---
>   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,
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.