All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] btrfs path auto free
@ 2024-09-03 18:19 Leo Martins
  2024-09-03 18:19 ` [PATCH v4 1/3] btrfs: DEFINE_FREE for btrfs_free_path Leo Martins
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Leo Martins @ 2024-09-03 18:19 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

CHANGELOG:
Patch 1/3
	- Move BTRFS_PATH_AUTO_FREE macro definition next to btrfs_path
	  struct.

The DEFINE_FREE macro defines a wrapper function for a given memory
cleanup function which takes a pointer as an argument and calls the
cleanup function with the value of the pointer. The __free macro adds
a scoped-based cleanup to a variable, using the __cleanup attribute
to specify the cleanup function that should be called when the variable
goes out of scope.

Using this cleanup code pattern ensures that memory is properly freed
when it's no longer needed, preventing memory leaks and reducing the
risk of crashes or other issues caused by incorrect memory management.
Even if the code is already memory safe, using this pattern reduces
the risk of introducing memory-related bugs in the future

In this series of patches I've added a DEFINE_FREE for btrfs_free_path
and created a macro BTRFS_PATH_AUTO_FREE to clearly identify path
declarations that will be automatically freed.

I've included some simple examples of where this pattern can be used.
The trivial examples are ones where there is one exit path and the only
cleanup performed is a call to btrfs_free_path.

Leo Martins (3):
  btrfs: DEFINE_FREE for btrfs_free_path
  btrfs: BTRFS_PATH_AUTO_FREE in zoned.c
  btrfs: BTRFS_PATH_AUTO_FREE in orphan.c

 fs/btrfs/ctree.c  |  2 +-
 fs/btrfs/ctree.h  |  5 +++++
 fs/btrfs/orphan.c | 19 ++++++-------------
 fs/btrfs/zoned.c  | 34 +++++++++++-----------------------
 4 files changed, 23 insertions(+), 37 deletions(-)

-- 
2.43.5


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-09-04 16:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-03 18:19 [PATCH v4 0/3] btrfs path auto free Leo Martins
2024-09-03 18:19 ` [PATCH v4 1/3] btrfs: DEFINE_FREE for btrfs_free_path Leo Martins
2024-09-03 18:19 ` [PATCH v4 2/3] btrfs: BTRFS_PATH_AUTO_FREE in zoned.c Leo Martins
2024-09-03 18:19 ` [PATCH v4 3/3] btrfs: BTRFS_PATH_AUTO_FREE in orphan.c Leo Martins
2024-09-04 16:58 ` [PATCH v4 0/3] btrfs path auto free David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.