btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_run_dev_replace()
authorDavid Sterba <dsterba@suse.com>
Mon, 24 Feb 2025 08:15:17 +0000 (09:15 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Mar 2025 19:35:47 +0000 (20:35 +0100)
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/dev-replace.c

index 147c5494adf910e8dfceb4d7e5f6f54de684e20f..1a82e88ec5c196a2dd841fcf3039095c00b4f55d 100644 (file)
@@ -341,7 +341,7 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
        struct btrfs_fs_info *fs_info = trans->fs_info;
        int ret;
        struct btrfs_root *dev_root = fs_info->dev_root;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct btrfs_key key;
        struct extent_buffer *eb;
        struct btrfs_dev_replace_item *ptr;
@@ -360,16 +360,15 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
        key.offset = 0;
 
        path = btrfs_alloc_path();
-       if (!path) {
-               ret = -ENOMEM;
-               goto out;
-       }
+       if (!path)
+               return -ENOMEM;
+
        ret = btrfs_search_slot(trans, dev_root, &key, path, -1, 1);
        if (ret < 0) {
                btrfs_warn(fs_info,
                           "error %d while searching for dev_replace item!",
                           ret);
-               goto out;
+               return ret;
        }
 
        if (ret == 0 &&
@@ -390,7 +389,7 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
                        btrfs_warn(fs_info,
                                   "delete too small dev_replace item failed %d!",
                                   ret);
-                       goto out;
+                       return ret;
                }
                ret = 1;
        }
@@ -403,7 +402,7 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
                if (ret < 0) {
                        btrfs_warn(fs_info,
                                   "insert dev_replace item failed %d!", ret);
-                       goto out;
+                       return ret;
                }
        }
 
@@ -435,8 +434,6 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
                dev_replace->cursor_right);
        dev_replace->item_needs_writeback = 0;
        up_write(&dev_replace->rwsem);
-out:
-       btrfs_free_path(path);
 
        return ret;
 }