@@ -196,7 +196,7 @@ struct btrfs_path *btrfs_alloc_path(void)
/* this also releases the path */
void btrfs_free_path(struct btrfs_path *p)
{
- if (!p)
+ if (IS_ERR_OR_NULL(p))
return;
btrfs_release_path(p);
kmem_cache_free(btrfs_path_cachep, p);
@@ -6,6 +6,7 @@
#ifndef BTRFS_CTREE_H
#define BTRFS_CTREE_H
+#include "linux/cleanup.h"
#include <linux/pagemap.h>
#include <linux/spinlock.h>
#include <linux/rbtree.h>
@@ -599,6 +600,9 @@ int btrfs_search_slot_for_read(struct btrfs_root *root,
void btrfs_release_path(struct btrfs_path *p);
struct btrfs_path *btrfs_alloc_path(void);
void btrfs_free_path(struct btrfs_path *p);
+DEFINE_FREE(btrfs_free_path, struct btrfs_path *, btrfs_free_path(_T))
+#define BTRFS_PATH_AUTO_FREE(path_name) \
+ struct btrfs_path *path_name __free(btrfs_free_path) = NULL;
int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_path *path, int slot, int nr);
Add a DEFINE_FREE for btrfs_free_path. This defines a function that can be called using the __free attribute. Defined a macro BTRFS_PATH_AUTO_FREE to make the declaration of an auto freeing path very clear. Signed-off-by: Leo Martins <loemra.dev@gmail.com> --- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)