Re: [PATCH v3 02/12] btrfs: implement a nowait option for tree searches

David Sterba
2022-09-26T12:28:10Z

On Mon, Sep 26, 2022 at 10:14:40AM +0100, Filipe Manana wrote:
> On Mon, Sep 12, 2022 at 12:27:42PM -0700, Stefan Roesch wrote:
> > From: Josef Bacik <josef@toxicpanda.com>
> > +{
> > + struct extent_buffer *eb;
> > +
> > + while (1) {
> > + eb = btrfs_root_node(root);
> > + if (!btrfs_try_tree_read_lock(eb))
> > + return ERR_PTR(-EAGAIN);
>
> There's a leak of the extent buffer here.
> This fixes it up:
>
> diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c
> index 9d53bcfb6d9b..0eab3cb274a1 100644
> --- a/fs/btrfs/locking.c
> +++ b/fs/btrfs/locking.c
> @@ -298,8 +298,10 @@ struct extent_buffer *btrfs_try_read_lock_root_node(struct btrfs_root *root)
>
> while (1) {
> eb = btrfs_root_node(root);
> - if (!btrfs_try_tree_read_lock(eb))
> + if (!btrfs_try_tree_read_lock(eb)) {
> + free_extent_buffer(eb);
> return ERR_PTR(-EAGAIN);
> + }
> if (eb == root->node)
> break;
> btrfs_tree_read_unlock(eb);

Folded to the commit, thanks.