Kernel: Tidy up AnonymousFile construction a bit

- Rename create() => try_create()
- Use adopt_nonnull_ref_or_enomem()
This commit is contained in:
Andreas Kling 2021-09-05 14:33:25 +02:00
parent 9a1fdb523f
commit 4012099338
Notes: sideshowbarker 2024-07-18 04:43:25 +09:00
2 changed files with 6 additions and 6 deletions

View File

@ -13,9 +13,9 @@ namespace Kernel {
class AnonymousFile final : public File {
public:
static RefPtr<AnonymousFile> create(NonnullRefPtr<Memory::AnonymousVMObject> vmobject)
static KResultOr<NonnullRefPtr<AnonymousFile>> try_create(NonnullRefPtr<Memory::AnonymousVMObject> vmobject)
{
return adopt_ref_if_nonnull(new (nothrow) AnonymousFile(move(vmobject)));
return adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousFile(move(vmobject)));
}
virtual ~AnonymousFile() override;

View File

@ -33,10 +33,10 @@ KResultOr<FlatPtr> Process::sys$anon_create(size_t size, int options)
if (maybe_vmobject.is_error())
return maybe_vmobject.error();
auto anon_file = AnonymousFile::create(maybe_vmobject.release_value());
if (!anon_file)
return ENOMEM;
auto description_or_error = FileDescription::try_create(*anon_file);
auto anon_file_or_error = AnonymousFile::try_create(maybe_vmobject.release_value());
if (anon_file_or_error.is_error())
return anon_file_or_error.error();
auto description_or_error = FileDescription::try_create(anon_file_or_error.release_value());
if (description_or_error.is_error())
return description_or_error.error();