btrfs: use free_root_extent_buffer to free root
diff mbox series

Message ID 20200623084007.34215-1-johannes.thumshirn@wdc.com
State New
Headers show
Series
  • btrfs: use free_root_extent_buffer to free root
Related show

Commit Message

Johannes Thumshirn June 23, 2020, 8:40 a.m. UTC
In btrfs_put_root() we're freeing a btrfs_root's 'node' and 'commit_root'
extent buffers manually via kfree(), while we're using
free_root_extent_buffers() in the free_root_pointers() function above.

free_root_extent_buffers() also NULLs the pointers after freeing, which
mitigates potential double frees.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/disk-io.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Anand Jain June 23, 2020, 1:57 p.m. UTC | #1
Looks good.
Reviewed-by: Anand Jain <annad.jain@oracle.com>
David Sterba June 23, 2020, 3:32 p.m. UTC | #2
On Tue, Jun 23, 2020 at 05:40:07PM +0900, Johannes Thumshirn wrote:
> In btrfs_put_root() we're freeing a btrfs_root's 'node' and 'commit_root'
> extent buffers manually via kfree(), while we're using
> free_root_extent_buffers() in the free_root_pointers() function above.
> 
> free_root_extent_buffers() also NULLs the pointers after freeing, which
> mitigates potential double frees.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Added to misc-next, thanks.

Patch
diff mbox series

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index c70d47b8090a..b86961309b0d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2001,8 +2001,7 @@  void btrfs_put_root(struct btrfs_root *root)
 		if (root->anon_dev)
 			free_anon_bdev(root->anon_dev);
 		btrfs_drew_lock_destroy(&root->snapshot_lock);
-		free_extent_buffer(root->node);
-		free_extent_buffer(root->commit_root);
+		free_root_extent_buffers(root);
 		kfree(root->free_ino_ctl);
 		kfree(root->free_ino_pinned);
 #ifdef CONFIG_BTRFS_DEBUG