From: "Miquel Sabaté Solà" <mssola@mssola.com>
To: Filipe Manana <fdmanana@kernel.org>
Cc: dsterba@suse.com, clm@fb.com, linux-btrfs@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: free pages on error on 'btrfs_uring_read_extent'
Date: Tue, 17 Feb 2026 12:22:47 +0100 [thread overview]
Message-ID: <87o6lnty0o.fsf@> (raw)
In-Reply-To: <CAL3q7H7kyo5hEEhn_RO2=55qyAr_6=duS=VQB79wHwNggf+bcA@mail.gmail.com> (Filipe Manana's message of "Tue, 17 Feb 2026 11:10:38 +0000")
[-- Attachment #1: Type: text/plain, Size: 2880 bytes --]
Filipe Manana @ 2026-02-17 11:10 GMT:
> On Mon, Feb 16, 2026 at 9:13 PM Miquel Sabaté Solà <mssola@mssola.com> wrote:
>>
>
> As for the subject, should be instead:
>
> btrfs: free pages on error in btrfs_read_uring_extent()
>
> Note we don't usually surround function names with quotes and we
> usually add the () after their name.
>
>> In this function the 'pages' object is never freed in the hopes that is
>
> that is -> that it is
>
>> picked up by btrfs_uring_read_finished() whenever that executes in the
>> future. But that's just the happy path. Along the way previous
>> allocations might have gone wrong, or we might not get -EIOCBQUEUED from
>> btrfs_encoded_read_regular_fill_pages(). In all these cases, we go to a
>> cleanup section that frees all memory allocated by this function without
>> assuming any deferred execution, and this also needs to happen for the
>> 'pages' allocation.
>>
>> Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
>
> Not contrary to what you had just suggested for a cleanup patch here:
> https://lore.kernel.org/linux-btrfs/87tsvfu11i.fsf@/
>
> This is the sort of change that should have a Fixes tag, because it
> fixes a bug, something that affects users, therefore useful and
> important to have backported to stable releases.
>
> So adding a:
>
> Fixes: 34310c442e17 ("btrfs: add io_uring command for encoded reads
> (ENCODED_READ ioctl)")
>
> You don't need to do any of these changes, I've done that changes
> myself and added it to the github for-next branch, thanks.
>
> Reviewed-by: Filipe Manana <fdmanana@suse.com>
>
>
You are totally right, completely missed that one.
Thanks!
Miquel
>> ---
>> fs/btrfs/ioctl.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>> index 38d93dae71ca..b3e8a8d9b19d 100644
>> --- a/fs/btrfs/ioctl.c
>> +++ b/fs/btrfs/ioctl.c
>> @@ -4651,7 +4651,7 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
>> {
>> struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp));
>> struct extent_io_tree *io_tree = &inode->io_tree;
>> - struct page **pages;
>> + struct page **pages = NULL;
>> struct btrfs_uring_priv *priv = NULL;
>> unsigned long nr_pages;
>> int ret;
>> @@ -4709,6 +4709,11 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
>> btrfs_unlock_extent(io_tree, start, lockend, &cached_state);
>> btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
>> kfree(priv);
>> + for (int i = 0; i < nr_pages; i++) {
>> + if (pages[i])
>> + __free_page(pages[i]);
>> + }
>> + kfree(pages);
>> return ret;
>> }
>>
>> --
>> 2.53.0
>>
>>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 897 bytes --]
prev parent reply other threads:[~2026-02-17 11:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-16 21:12 [PATCH] btrfs: free pages on error on 'btrfs_uring_read_extent' Miquel Sabaté Solà
2026-02-17 11:10 ` Filipe Manana
2026-02-17 11:22 ` Miquel Sabaté Solà [this message]
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=87o6lnty0o.fsf@ \
--to=mssola@mssola.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=fdmanana@kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 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.