diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-07 13:57:33 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-07 13:58:16 +0200 |
commit | 631b8e90cd1c271e23d92c46f578fc9cd6dbb81d (patch) | |
tree | 22d0de17fd1df53f90c1df8393543e028a575a3b /Kernel/TTY | |
parent | 01993d0af34bb41c9ac8363e2fb584f42e191d38 (diff) | |
download | serenity-631b8e90cd1c271e23d92c46f578fc9cd6dbb81d.zip |
Kernel: Use KResultOr and TRY() for MasterPTY
Diffstat (limited to 'Kernel/TTY')
-rw-r--r-- | Kernel/TTY/MasterPTY.cpp | 18 | ||||
-rw-r--r-- | Kernel/TTY/MasterPTY.h | 2 | ||||
-rw-r--r-- | Kernel/TTY/PTYMultiplexer.cpp | 4 |
3 files changed, 6 insertions, 18 deletions
diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index d539cbc5f9..20b5573927 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -16,22 +16,12 @@ namespace Kernel { -RefPtr<MasterPTY> MasterPTY::try_create(unsigned int index) +KResultOr<NonnullRefPtr<MasterPTY>> MasterPTY::try_create(unsigned int index) { - auto buffer_or_error = DoubleBuffer::try_create(); - if (buffer_or_error.is_error()) - return {}; - - auto master_pty = adopt_ref_if_nonnull(new (nothrow) MasterPTY(index, buffer_or_error.release_value())); - if (!master_pty) - return {}; - - auto slave_pty = adopt_ref_if_nonnull(new (nothrow) SlavePTY(*master_pty, index)); - if (!slave_pty) - return {}; - + auto buffer = TRY(DoubleBuffer::try_create()); + auto master_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MasterPTY(index, move(buffer)))); + auto slave_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, index))); master_pty->m_slave = slave_pty; - return master_pty; } diff --git a/Kernel/TTY/MasterPTY.h b/Kernel/TTY/MasterPTY.h index 677bea7d3a..0763654ed6 100644 --- a/Kernel/TTY/MasterPTY.h +++ b/Kernel/TTY/MasterPTY.h @@ -16,7 +16,7 @@ class SlavePTY; class MasterPTY final : public CharacterDevice { public: - [[nodiscard]] static RefPtr<MasterPTY> try_create(unsigned index); + static KResultOr<NonnullRefPtr<MasterPTY>> try_create(unsigned index); virtual ~MasterPTY() override; unsigned index() const { return m_index; } diff --git a/Kernel/TTY/PTYMultiplexer.cpp b/Kernel/TTY/PTYMultiplexer.cpp index 537831b74d..4cb2e2c10c 100644 --- a/Kernel/TTY/PTYMultiplexer.cpp +++ b/Kernel/TTY/PTYMultiplexer.cpp @@ -42,9 +42,7 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options) return EBUSY; auto master_index = freelist.take_last(); - auto master = MasterPTY::try_create(master_index); - if (!master) - return ENOMEM; + auto master = TRY(MasterPTY::try_create(master_index)); dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index()); auto description = TRY(OpenFileDescription::try_create(*master)); description->set_rw_mode(options); |