These are two simple macros which ensure that a pointer is initialized
to NULL and with the proper cleanup attribute for it.
Suggested-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
---
fs/btrfs/misc.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/btrfs/misc.h b/fs/btrfs/misc.h
index 60f9b000d644..0e33327e70d9 100644
--- a/fs/btrfs/misc.h
+++ b/fs/btrfs/misc.h
@@ -13,6 +13,13 @@
#include <linux/rbtree.h>
#include <linux/bio.h>
+/*
+ * Convenient macros to define a pointer with the __free(kfree) and
+ * __free(kvfree) cleanup attributes and initialized to NULL.
+ */
+#define AUTO_KFREE_PTR(name) *name __free(kfree) = NULL
+#define AUTO_KVFREE_PTR(name) *name __free(kvfree) = NULL
+
/*
* Enumerate bits using enum autoincrement. Define the @name as the n-th bit.
*/
--
2.51.1