Re: [PATCH 2/4] btrfs: use BTRFS_PATH_AUTO_FREE in del_balance_item()

From: Filipe Manana
Date: Tue Apr 08 2025 - 10:52:57 EST


On Tue, Apr 8, 2025 at 1:18 PM Yangtao Li <frank.li@xxxxxxxx> wrote:
>
> All cleanup paths lead to btrfs_path_free so we can define path with the
> automatic free callback.
>
> Signed-off-by: Yangtao Li <frank.li@xxxxxxxx>
> ---
> fs/btrfs/volumes.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index a962efaec4ea..375d92720e17 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -3775,7 +3775,7 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
> {
> struct btrfs_root *root = fs_info->tree_root;
> struct btrfs_trans_handle *trans;
> - struct btrfs_path *path;
> + BTRFS_PATH_AUTO_FREE(path);
> struct btrfs_key key;
> int ret, err;
>
> @@ -3784,10 +3784,8 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
> return -ENOMEM;
>
> trans = btrfs_start_transaction_fallback_global_rsv(root, 0);
> - if (IS_ERR(trans)) {
> - btrfs_free_path(path);
> + if (IS_ERR(trans))
> return PTR_ERR(trans);
> - }
>
> key.objectid = BTRFS_BALANCE_OBJECTID;
> key.type = BTRFS_TEMPORARY_ITEM_KEY;
> @@ -3803,7 +3801,6 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
>
> ret = btrfs_del_item(trans, root, path);
> out:
> - btrfs_free_path(path);
> err = btrfs_commit_transaction(trans);

Exactly the same comment as for the previous patch -
https://lore.kernel.org/linux-btrfs/CAL3q7H6ysGxpXs8P9iPY-Y1KNKPggGSFHR_tMv-34Q+Qf6PZTQ@xxxxxxxxxxxxxx/
This can result in a deadlock.

Thanks.


> if (err && !ret)
> ret = err;
> --
> 2.39.0
>
>