diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-08-01 02:21:20 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-03 18:54:23 +0200 |
commit | 15cd5d324c9b8803fd6d7b4e9581da1375963bbe (patch) | |
tree | ae8e0e9986864d75a87999ebdb51575840ab87ef /Kernel/FileSystem/Ext2FileSystem.cpp | |
parent | 43f930d3aacf64b4cbf28e95bd4ef8292e2e6011 (diff) | |
download | serenity-15cd5d324c9b8803fd6d7b4e9581da1375963bbe.zip |
Kernel: Handle OOM from KBuffer usage in Ext2FS::get_bitmap_block()
Fixes up error handling on an OOM-able path, and removes one more usage
of KBuffer::create_with_size.
Diffstat (limited to 'Kernel/FileSystem/Ext2FileSystem.cpp')
-rw-r--r-- | Kernel/FileSystem/Ext2FileSystem.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index c199cfe611..579f5e2f29 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -701,7 +701,7 @@ void Ext2FS::flush_writes() } for (auto& cached_bitmap : m_cached_bitmaps) { if (cached_bitmap->dirty) { - auto buffer = UserOrKernelBuffer::for_kernel_buffer(cached_bitmap->buffer.data()); + auto buffer = UserOrKernelBuffer::for_kernel_buffer(cached_bitmap->buffer->data()); if (auto result = write_block(cached_bitmap->bitmap_block_index, buffer, block_size()); result.is_error()) { dbgln("Ext2FS[{}]::flush_writes(): Failed to write blocks: {}", fsid(), result.error()); } @@ -1499,13 +1499,15 @@ KResultOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_bloc return cached_bitmap; } - auto block = KBuffer::create_with_size(block_size(), Region::Access::Read | Region::Access::Write, "Ext2FS: Cached bitmap block"); - auto buffer = UserOrKernelBuffer::for_kernel_buffer(block.data()); + auto block = KBuffer::try_create_with_size(block_size(), Region::Access::Read | Region::Access::Write, "Ext2FS: Cached bitmap block"); + if (!block) + return ENOMEM; + auto buffer = UserOrKernelBuffer::for_kernel_buffer(block->data()); if (auto result = read_block(bitmap_block_index, &buffer, block_size()); result.is_error()) { dbgln("Ext2FS: Failed to load bitmap block {}", bitmap_block_index); return result; } - auto new_bitmap = adopt_own_if_nonnull(new (nothrow) CachedBitmap(bitmap_block_index, move(block))); + auto new_bitmap = adopt_own_if_nonnull(new (nothrow) CachedBitmap(bitmap_block_index, block.release_nonnull())); if (!new_bitmap) return ENOMEM; if (!m_cached_bitmaps.try_append(move(new_bitmap))) |