mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:57:44 +00:00
Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
This commit is contained in:
parent
140f1d9e55
commit
45cf40653a
79 changed files with 202 additions and 274 deletions
|
@ -381,8 +381,8 @@ UNMAP_AFTER_INIT void IDEChannel::detect_disks()
|
|||
}
|
||||
|
||||
// FIXME: Handle possible OOM situation here.
|
||||
ByteBuffer wbuf = ByteBuffer::create_uninitialized(512).release_value();
|
||||
ByteBuffer bbuf = ByteBuffer::create_uninitialized(512).release_value();
|
||||
ByteBuffer wbuf = ByteBuffer::create_uninitialized(512).release_value_but_fixme_should_propagate_errors();
|
||||
ByteBuffer bbuf = ByteBuffer::create_uninitialized(512).release_value_but_fixme_should_propagate_errors();
|
||||
u8* b = bbuf.data();
|
||||
u16* w = (u16*)wbuf.data();
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ UNMAP_AFTER_INIT ErrorOr<void> NVMeController::identify_and_init_namespaces()
|
|||
|
||||
RefPtr<Memory::PhysicalPage> prp_dma_buffer;
|
||||
OwnPtr<Memory::Region> prp_dma_region;
|
||||
auto namespace_data_struct = ByteBuffer::create_zeroed(NVMe_IDENTIFY_SIZE).release_value();
|
||||
auto namespace_data_struct = TRY(ByteBuffer::create_zeroed(NVMe_IDENTIFY_SIZE));
|
||||
u32 active_namespace_list[NVMe_IDENTIFY_SIZE / sizeof(u32)];
|
||||
|
||||
{
|
||||
|
|
|
@ -59,7 +59,7 @@ GUIDPartitionTable::GUIDPartitionTable(const StorageDevice& device)
|
|||
: MBRPartitionTable(device)
|
||||
{
|
||||
// FIXME: Handle OOM failure here.
|
||||
m_cached_header = ByteBuffer::create_zeroed(m_device->block_size()).release_value();
|
||||
m_cached_header = ByteBuffer::create_zeroed(m_device->block_size()).release_value_but_fixme_should_propagate_errors();
|
||||
VERIFY(partitions_count() == 0);
|
||||
if (!initialize())
|
||||
m_valid = false;
|
||||
|
@ -89,7 +89,7 @@ bool GUIDPartitionTable::initialize()
|
|||
}
|
||||
|
||||
auto entries_buffer_result = ByteBuffer::create_zeroed(m_device->block_size());
|
||||
if (!entries_buffer_result.has_value()) {
|
||||
if (entries_buffer_result.is_error()) {
|
||||
dbgln("GUIPartitionTable: not enough memory for entries buffer");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ bool MBRPartitionTable::read_boot_record()
|
|||
MBRPartitionTable::MBRPartitionTable(const StorageDevice& device, u32 start_lba)
|
||||
: PartitionTable(device)
|
||||
, m_start_lba(start_lba)
|
||||
, m_cached_header(ByteBuffer::create_zeroed(m_device->block_size()).release_value()) // FIXME: Do something sensible if this fails because of OOM.
|
||||
, m_cached_header(ByteBuffer::create_zeroed(m_device->block_size()).release_value_but_fixme_should_propagate_errors()) // FIXME: Do something sensible if this fails because of OOM.
|
||||
{
|
||||
if (!read_boot_record() || !initialize())
|
||||
return;
|
||||
|
@ -68,7 +68,7 @@ MBRPartitionTable::MBRPartitionTable(const StorageDevice& device, u32 start_lba)
|
|||
MBRPartitionTable::MBRPartitionTable(const StorageDevice& device)
|
||||
: PartitionTable(device)
|
||||
, m_start_lba(0)
|
||||
, m_cached_header(ByteBuffer::create_zeroed(m_device->block_size()).release_value()) // FIXME: Do something sensible if this fails because of OOM.
|
||||
, m_cached_header(ByteBuffer::create_zeroed(m_device->block_size()).release_value_but_fixme_should_propagate_errors()) // FIXME: Do something sensible if this fails because of OOM.
|
||||
{
|
||||
if (!read_boot_record() || contains_ebr() || is_protective_mbr() || !initialize())
|
||||
return;
|
||||
|
|
|
@ -62,10 +62,7 @@ ErrorOr<size_t> StorageDevice::read(OpenFileDescription&, u64 offset, UserOrKern
|
|||
off_t pos = whole_blocks * block_size();
|
||||
|
||||
if (remaining > 0) {
|
||||
auto data_result = ByteBuffer::create_uninitialized(block_size());
|
||||
if (!data_result.has_value())
|
||||
return ENOMEM;
|
||||
auto data = data_result.release_value();
|
||||
auto data = TRY(ByteBuffer::create_uninitialized(block_size()));
|
||||
auto data_buffer = UserOrKernelBuffer::for_kernel_buffer(data.data());
|
||||
auto read_request = TRY(try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index + whole_blocks, 1, data_buffer, block_size()));
|
||||
auto result = read_request->wait();
|
||||
|
@ -133,7 +130,7 @@ ErrorOr<size_t> StorageDevice::write(OpenFileDescription&, u64 offset, const Use
|
|||
// then write the whole block back to the disk.
|
||||
if (remaining > 0) {
|
||||
// FIXME: Do something sensible with this OOM scenario.
|
||||
auto data = ByteBuffer::create_zeroed(block_size()).release_value();
|
||||
auto data = ByteBuffer::create_zeroed(block_size()).release_value_but_fixme_should_propagate_errors();
|
||||
auto data_buffer = UserOrKernelBuffer::for_kernel_buffer(data.data());
|
||||
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue