From 274d535d0e1710fe5819a7464b762c244bed664b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 6 Sep 2021 20:23:08 +0200 Subject: [PATCH] Kernel: Use TRY() in sys$module_load() and sys$module_unload() --- Kernel/Syscalls/module.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/Kernel/Syscalls/module.cpp b/Kernel/Syscalls/module.cpp index 471dffd803..359b094607 100644 --- a/Kernel/Syscalls/module.cpp +++ b/Kernel/Syscalls/module.cpp @@ -23,22 +23,13 @@ KResultOr Process::sys$module_load(Userspace user_path, si REQUIRE_NO_PROMISES; - auto path = get_syscall_path_argument(user_path, path_length); - if (path.is_error()) - return path.error(); - auto description_or_error = VirtualFileSystem::the().open(path.value()->view(), O_RDONLY, 0, current_directory()); - if (description_or_error.is_error()) - return description_or_error.error(); - auto& description = description_or_error.value(); - auto payload_or_error = description->read_entire_file(); - if (payload_or_error.is_error()) - return payload_or_error.error(); + auto path = TRY(get_syscall_path_argument(user_path, path_length)); + auto description = TRY(VirtualFileSystem::the().open(path->view(), O_RDONLY, 0, current_directory())); + auto payload = TRY(description->read_entire_file()); - auto& payload = *payload_or_error.value(); - auto storage = KBuffer::try_create_with_size(payload.size()); + auto storage = KBuffer::try_create_with_bytes(ReadonlyBytes { payload->data(), payload->size() }); if (!storage) return ENOMEM; - memcpy(storage->data(), payload.data(), payload.size()); auto elf_image = try_make(storage->data(), storage->size()); if (!elf_image) @@ -155,11 +146,9 @@ KResultOr Process::sys$module_unload(Userspace user_name, REQUIRE_NO_PROMISES; - auto module_name_or_error = try_copy_kstring_from_user(user_name, name_length); - if (module_name_or_error.is_error()) - return module_name_or_error.error(); + auto module_name = TRY(try_copy_kstring_from_user(user_name, name_length)); - auto it = g_modules->find(module_name_or_error.value()->view()); + auto it = g_modules->find(module_name->view()); if (it == g_modules->end()) return ENOENT;