btrfs: push errors up from add_async_extent()

[ Upstream commit dbe6cda68f ]

The memory allocation error in add_async_extent() is not handled
properly, return an error and push the BUG_ON to the caller. Handling it
there is not trivial so at least make it visible.

Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
David Sterba 2024-01-24 17:26:25 +01:00 committed by Greg Kroah-Hartman
parent 981a749cef
commit 6be930556d

View File

@ -730,7 +730,8 @@ static noinline int add_async_extent(struct async_chunk *cow,
struct async_extent *async_extent; struct async_extent *async_extent;
async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS); async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS);
BUG_ON(!async_extent); /* -ENOMEM */ if (!async_extent)
return -ENOMEM;
async_extent->start = start; async_extent->start = start;
async_extent->ram_size = ram_size; async_extent->ram_size = ram_size;
async_extent->compressed_size = compressed_size; async_extent->compressed_size = compressed_size;
@ -1017,8 +1018,9 @@ again:
* The async work queues will take care of doing actual allocation on * The async work queues will take care of doing actual allocation on
* disk for these compressed pages, and will submit the bios. * disk for these compressed pages, and will submit the bios.
*/ */
add_async_extent(async_chunk, start, total_in, total_compressed, pages, ret = add_async_extent(async_chunk, start, total_in, total_compressed, pages,
nr_pages, compress_type); nr_pages, compress_type);
BUG_ON(ret);
if (start + total_in < end) { if (start + total_in < end) {
start += total_in; start += total_in;
cond_resched(); cond_resched();
@ -1030,8 +1032,9 @@ mark_incompressible:
if (!btrfs_test_opt(fs_info, FORCE_COMPRESS) && !inode->prop_compress) if (!btrfs_test_opt(fs_info, FORCE_COMPRESS) && !inode->prop_compress)
inode->flags |= BTRFS_INODE_NOCOMPRESS; inode->flags |= BTRFS_INODE_NOCOMPRESS;
cleanup_and_bail_uncompressed: cleanup_and_bail_uncompressed:
add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0, ret = add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
BTRFS_COMPRESS_NONE); BTRFS_COMPRESS_NONE);
BUG_ON(ret);
free_pages: free_pages:
if (pages) { if (pages) {
for (i = 0; i < nr_pages; i++) { for (i = 0; i < nr_pages; i++) {