]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: introduce BTRFS_PATH_AUTO_RELEASE() helper
authorQu Wenruo <wqu@suse.com>
Tue, 25 Nov 2025 21:50:21 +0000 (08:20 +1030)
committerDavid Sterba <dsterba@suse.com>
Tue, 3 Feb 2026 05:38:32 +0000 (06:38 +0100)
commitfab0c0f03cfd0dfe793889e3374ebc68ecf18889
treeb15d7f6c168ba0953aaf558b108648959276f149
parentddea91780fecd349eb4b2c4036bfbf1ab5f75321
btrfs: introduce BTRFS_PATH_AUTO_RELEASE() helper

There are already several bugs with on-stack btrfs_path involved, even
it is already a little safer than btrfs_path pointers (only leaks the
extent buffers, not the btrfs_path structure itself)

- Patch "btrfs: make sure extent and csum paths are always released in
  scrub_raid56_parity_stripe()"

- Patch "btrfs: fix a potential path leak in print_data_reloc_error()"

Thus there is a real need to apply auto release for those on-stack paths.

Introduces a new macro, BTRFS_PATH_AUTO_RELEASE() which defines one
on-stack btrfs_path structure, initialize it all to 0, then call
btrfs_release_path() on it when exiting the scope.

This applies to current 3 on-stack path usages:

- defrag_get_extent() in defrag.c

- print_data_reloc_error() in inode.c
  There is a special case where we want to release the path early before
  the time consuming iterate_extent_inodes() call, thus that manual
  early release is kept as is, with an extra comment added.

- scrub_radi56_parity_stripe() in scrub.c

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/defrag.c
fs/btrfs/inode.c
fs/btrfs/scrub.c