summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-08-01 02:21:20 -0700
committerAndreas Kling <kling@serenityos.org>2021-08-03 18:54:23 +0200
commit15cd5d324c9b8803fd6d7b4e9581da1375963bbe (patch)
treeae8e0e9986864d75a87999ebdb51575840ab87ef /Kernel
parent43f930d3aacf64b4cbf28e95bd4ef8292e2e6011 (diff)
downloadserenity-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')
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp10
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.h6
2 files changed, 9 insertions, 7 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)))
diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h
index d3318ab2e4..d3f1161087 100644
--- a/Kernel/FileSystem/Ext2FileSystem.h
+++ b/Kernel/FileSystem/Ext2FileSystem.h
@@ -168,15 +168,15 @@ private:
bool m_block_group_descriptors_dirty { false };
struct CachedBitmap {
- CachedBitmap(BlockIndex bi, KBuffer&& buf)
+ CachedBitmap(BlockIndex bi, NonnullOwnPtr<KBuffer> buf)
: bitmap_block_index(bi)
, buffer(move(buf))
{
}
BlockIndex bitmap_block_index { 0 };
bool dirty { false };
- KBuffer buffer;
- BitmapView bitmap(u32 blocks_per_group) { return BitmapView { buffer.data(), blocks_per_group }; }
+ NonnullOwnPtr<KBuffer> buffer;
+ BitmapView bitmap(u32 blocks_per_group) { return BitmapView { buffer->data(), blocks_per_group }; }
};
KResultOr<CachedBitmap*> get_bitmap_block(BlockIndex);