Kernel/Net: Make the LoopbackAdapter initializer to use ErrorOr pattern

This looks much more nice, and also matches our pattern for other types
of network adapters' initializers.
This commit is contained in:
Liav A 2023-04-11 03:44:55 +03:00 committed by Linus Groh
parent 9f011592be
commit bd7d4513bf
Notes: sideshowbarker 2024-07-17 20:19:08 +09:00
3 changed files with 6 additions and 9 deletions

View file

@ -11,12 +11,10 @@ namespace Kernel {
static bool s_loopback_initialized = false;
LockRefPtr<LoopbackAdapter> LoopbackAdapter::try_create()
ErrorOr<NonnullRefPtr<LoopbackAdapter>> LoopbackAdapter::try_create()
{
auto interface_name = KString::try_create("loop"sv);
if (interface_name.is_error())
return {};
return adopt_lock_ref_if_nonnull(new LoopbackAdapter(interface_name.release_value()));
auto interface_name = TRY(KString::try_create("loop"sv));
return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) LoopbackAdapter(move(interface_name))));
}
LoopbackAdapter::LoopbackAdapter(NonnullOwnPtr<KString> interface_name)

View file

@ -15,7 +15,7 @@ private:
LoopbackAdapter(NonnullOwnPtr<KString>);
public:
static LockRefPtr<LoopbackAdapter> try_create();
static ErrorOr<NonnullRefPtr<LoopbackAdapter>> try_create();
virtual ~LoopbackAdapter() override;
virtual ErrorOr<void> initialize(Badge<NetworkingManagement>) override { VERIFY_NOT_REACHED(); }

View file

@ -136,10 +136,9 @@ bool NetworkingManagement::initialize()
m_adapters.with([&](auto& adapters) { adapters.append(*result.release_value()); });
}));
}
auto loopback = LoopbackAdapter::try_create();
VERIFY(loopback);
auto loopback = MUST(LoopbackAdapter::try_create());
m_adapters.with([&](auto& adapters) { adapters.append(*loopback); });
m_loopback_adapter = loopback;
m_loopback_adapter = *loopback;
return true;
}
}