From 94a39db31d94bb60e257a5649b6cf2a873c820fc Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 26 Jan 2022 22:00:45 +0200 Subject: [PATCH] Kernel: Add try_create_device overload for static factory functions This makes sure DeviceManagement::try_create_device will call the static factory function (if available) instead of directly calling the constructor, which will allow us to move OOM-fallible calls out of Device constructors. --- Kernel/Devices/DeviceManagement.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Kernel/Devices/DeviceManagement.h b/Kernel/Devices/DeviceManagement.h index d0d1bce695..cd9746e6e8 100644 --- a/Kernel/Devices/DeviceManagement.h +++ b/Kernel/Devices/DeviceManagement.h @@ -55,6 +55,14 @@ public: ConsoleDevice const& console_device() const; ConsoleDevice& console_device(); + template + static inline ErrorOr> try_create_device(Args&&... args) requires(requires(Args... args) { DeviceType::try_create(args...); }) + { + auto device = TRY(DeviceType::try_create(forward(args)...)); + device->after_inserting(); + return device; + } + template static inline ErrorOr> try_create_device(Args&&... args) {