Skip to content

Commit 6288958

Browse files
mssolaSasha Levin
authored andcommitted
btrfs: free pages on error in btrfs_uring_read_extent()
[ Upstream commit 3f50141 ] In this function the 'pages' object is never freed in the hopes 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. Fixes: 34310c4 ("btrfs: add io_uring command for encoded reads (ENCODED_READ ioctl)") Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e109404 commit 6288958

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/btrfs/ioctl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4661,7 +4661,7 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
46614661
{
46624662
struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp));
46634663
struct extent_io_tree *io_tree = &inode->io_tree;
4664-
struct page **pages;
4664+
struct page **pages = NULL;
46654665
struct btrfs_uring_priv *priv = NULL;
46664666
unsigned long nr_pages;
46674667
int ret;
@@ -4719,6 +4719,11 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
47194719
btrfs_unlock_extent(io_tree, start, lockend, &cached_state);
47204720
btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
47214721
kfree(priv);
4722+
for (int i = 0; i < nr_pages; i++) {
4723+
if (pages[i])
4724+
__free_page(pages[i]);
4725+
}
4726+
kfree(pages);
47224727
return ret;
47234728
}
47244729

0 commit comments

Comments
 (0)