diff mbox series

[v2,3/3] btrfs: BTRFS_PATH_AUTO_FREE in orphan.c

Message ID b5ac0f327ed18a0b6ca9f7d22f3964ff3e1480ff.1724785204.git.loemra.dev@gmail.com (mailing list archive)
State New, archived
Headers show
Series btrfs path auto free | expand

Commit Message

Leo Martins Aug. 27, 2024, 7:08 p.m. UTC
Add automatic path freeing in orphan.c. This is the original example I
sent with only one exit point that just frees the path.
---
 fs/btrfs/orphan.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

Comments

Josef Bacik Aug. 27, 2024, 8:35 p.m. UTC | #1
On Tue, Aug 27, 2024 at 12:08:45PM -0700, Leo Martins wrote:
> Add automatic path freeing in orphan.c. This is the original example I
> sent with only one exit point that just frees the path.

We don't have context to what your other postings were when we're looking
through changelogs, simply write

Add automatic path freeing in orphan.c.  We only allocate a path twice in this
file and they're both simple with a single exit point.

Or something like that.  Thanks,

Josef
diff mbox series

Patch

diff --git a/fs/btrfs/orphan.c b/fs/btrfs/orphan.c
index 6195a2215b8fe..696dbaf26af52 100644
--- a/fs/btrfs/orphan.c
+++ b/fs/btrfs/orphan.c
@@ -9,7 +9,7 @@ 
 int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
 			     struct btrfs_root *root, u64 offset)
 {
-	struct btrfs_path *path;
+	BTRFS_PATH_AUTO_FREE(path);
 	struct btrfs_key key;
 	int ret = 0;
 
@@ -23,14 +23,13 @@  int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_insert_empty_item(trans, root, path, &key, 0);
 
-	btrfs_free_path(path);
 	return ret;
 }
 
 int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
 			  struct btrfs_root *root, u64 offset)
 {
-	struct btrfs_path *path;
+	BTRFS_PATH_AUTO_FREE(path);
 	struct btrfs_key key;
 	int ret = 0;
 
@@ -44,15 +43,9 @@  int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
 	if (ret < 0)
-		goto out;
-	if (ret) { /* JDM: Really? */
-		ret = -ENOENT;
-		goto out;
-	}
+		return ret;
+	if (ret)
+		return -ENOENT;
 
-	ret = btrfs_del_item(trans, root, path);
-
-out:
-	btrfs_free_path(path);
-	return ret;
+	return btrfs_del_item(trans, root, path);
 }