Skip to content

Commit 4c74a32

Browse files
loemrawkdave
authored andcommitted
btrfs: DEFINE_FREE for struct btrfs_path
Add a DEFINE_FREE for struct btrfs_path. This defines a function that can be called using the __free attribute. Define a macro BTRFS_PATH_AUTO_FREE to make the declaration of an auto freeing path very clear. The intended use is to define the auto free of path in cases where the path is allocated somewhere at the beginning and freed either on all error paths or at the end of the function. int func() { BTRFS_PATH_AUTO_FREE(path); if (...) return -ERROR; path = alloc_path(); ... if (...) return -ERROR; ... return 0; } Signed-off-by: Leo Martins <[email protected]> [ update changelog ] Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent ab6eac7 commit 4c74a32

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

fs/btrfs/ctree.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef BTRFS_CTREE_H
77
#define BTRFS_CTREE_H
88

9+
#include "linux/cleanup.h"
910
#include <linux/pagemap.h>
1011
#include <linux/spinlock.h>
1112
#include <linux/rbtree.h>
@@ -84,6 +85,9 @@ struct btrfs_path {
8485
unsigned int nowait:1;
8586
};
8687

88+
#define BTRFS_PATH_AUTO_FREE(path_name) \
89+
struct btrfs_path *path_name __free(btrfs_free_path) = NULL
90+
8791
/*
8892
* The state of btrfs root
8993
*/
@@ -598,6 +602,7 @@ int btrfs_search_slot_for_read(struct btrfs_root *root,
598602
void btrfs_release_path(struct btrfs_path *p);
599603
struct btrfs_path *btrfs_alloc_path(void);
600604
void btrfs_free_path(struct btrfs_path *p);
605+
DEFINE_FREE(btrfs_free_path, struct btrfs_path *, btrfs_free_path(_T))
601606

602607
int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
603608
struct btrfs_path *path, int slot, int nr);

0 commit comments

Comments
 (0)