Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: "Miquel Sabaté Solà" <mssola@mssola.com>
To: linux-btrfs@vger.kernel.org
Cc: clm@fb.com, dsterba@suse.com, johannes.thumshirn@wdc.com,
	fdmanana@suse.com, boris@bur.io, wqu@suse.com, neal@gompa.dev,
	linux-kernel@vger.kernel.org,
	"Miquel Sabaté Solà" <mssola@mssola.com>,
	"David Sterba" <dsterba@suse.cz>
Subject: [PATCH 2/4] btrfs: define the AUTO_K(V)FREE_PTR helper macros
Date: Tue, 21 Oct 2025 16:27:47 +0200	[thread overview]
Message-ID: <20251021142749.642956-3-mssola@mssola.com> (raw)
In-Reply-To: <20251021142749.642956-1-mssola@mssola.com>

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


  parent reply	other threads:[~2025-10-21 14:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21 14:27 [PATCH 0/4] btrfs: define and apply the AUTO_K(V)FREE_PTR macros Miquel Sabaté Solà
2025-10-21 14:27 ` [PATCH 1/4] btrfs: declare free_ipath() via DEFINE_FREE() instead Miquel Sabaté Solà
2025-10-22  7:31   ` David Sterba
2025-10-22  8:06     ` Daniel Vacek
2025-10-22  9:21     ` Miquel Sabaté Solà
2025-10-21 14:27 ` Miquel Sabaté Solà [this message]
2025-10-21 14:27 ` [PATCH 3/4] btrfs: apply the AUTO_K(V)FREE_PTR macros throughout the tree Miquel Sabaté Solà
2025-10-21 14:27 ` [PATCH 4/4] btrfs: add ASSERTs on prealloc in qgroup functions Miquel Sabaté Solà
2025-10-22  7:22 ` [PATCH 0/4] btrfs: define and apply the AUTO_K(V)FREE_PTR macros David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251021142749.642956-3-mssola@mssola.com \
    --to=mssola@mssola.com \
    --cc=boris@bur.io \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=dsterba@suse.cz \
    --cc=fdmanana@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neal@gompa.dev \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox