diff options
author | Andreas Kling <kling@serenityos.org> | 2021-11-08 00:51:39 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-08 01:10:53 +0100 |
commit | 79fa9765ca89869d19364143989436d117974c21 (patch) | |
tree | 3af62f70127d9217d841047f6b7461351800d1ae /Kernel/Devices/HID | |
parent | 7ee10c69264cb278845a1e1b06d5acf2e5e7ddf0 (diff) | |
download | serenity-79fa9765ca89869d19364143989436d117974c21.zip |
Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace!
This was a slightly tedious refactoring that took a long time, so it's
not unlikely that some bugs crept in.
Nevertheless, it does pass basic functionality testing, and it's just
real nice to finally see the same pattern in all contexts. :^)
Diffstat (limited to 'Kernel/Devices/HID')
-rw-r--r-- | Kernel/Devices/HID/HIDManagement.h | 2 | ||||
-rw-r--r-- | Kernel/Devices/HID/KeyboardDevice.cpp | 16 | ||||
-rw-r--r-- | Kernel/Devices/HID/KeyboardDevice.h | 6 | ||||
-rw-r--r-- | Kernel/Devices/HID/MouseDevice.cpp | 2 | ||||
-rw-r--r-- | Kernel/Devices/HID/MouseDevice.h | 4 |
5 files changed, 14 insertions, 16 deletions
diff --git a/Kernel/Devices/HID/HIDManagement.h b/Kernel/Devices/HID/HIDManagement.h index 864cfa7185..667acd7cf1 100644 --- a/Kernel/Devices/HID/HIDManagement.h +++ b/Kernel/Devices/HID/HIDManagement.h @@ -8,11 +8,11 @@ #include <AK/Atomic.h> #include <AK/CircularQueue.h> +#include <AK/Error.h> #include <AK/NonnullRefPtrVector.h> #include <AK/RefPtr.h> #include <AK/Time.h> #include <AK/Types.h> -#include <Kernel/API/KResult.h> #include <Kernel/API/KeyCode.h> #include <Kernel/API/MousePacket.h> #include <Kernel/Locking/Spinlock.h> diff --git a/Kernel/Devices/HID/KeyboardDevice.cpp b/Kernel/Devices/HID/KeyboardDevice.cpp index fd59ffe825..ff42ce3e9c 100644 --- a/Kernel/Devices/HID/KeyboardDevice.cpp +++ b/Kernel/Devices/HID/KeyboardDevice.cpp @@ -278,7 +278,7 @@ bool KeyboardDevice::can_read(const OpenFileDescription&, size_t) const return !m_queue.is_empty(); } -KResultOr<size_t> KeyboardDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size) +ErrorOr<size_t> KeyboardDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size) { size_t nread = 0; SpinlockLocker lock(m_queue_lock); @@ -292,13 +292,11 @@ KResultOr<size_t> KeyboardDevice::read(OpenFileDescription&, u64, UserOrKernelBu lock.unlock(); - auto result = buffer.write_buffered<sizeof(Event)>(sizeof(Event), [&](Bytes bytes) { + auto result = TRY(buffer.write_buffered<sizeof(Event)>(sizeof(Event), [&](Bytes bytes) { memcpy(bytes.data(), &event, sizeof(Event)); return bytes.size(); - }); - if (result.is_error()) - return result.error(); - VERIFY(result.value() == sizeof(Event)); + })); + VERIFY(result == sizeof(Event)); nread += sizeof(Event); lock.lock(); @@ -306,7 +304,7 @@ KResultOr<size_t> KeyboardDevice::read(OpenFileDescription&, u64, UserOrKernelBu return nread; } -KResult KeyboardDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) +ErrorOr<void> KeyboardDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) { switch (request) { case KEYBOARD_IOCTL_GET_NUM_LOCK: { @@ -319,7 +317,7 @@ KResult KeyboardDevice::ioctl(OpenFileDescription&, unsigned request, Userspace< if (num_lock_value != 0 && num_lock_value != 1) return EINVAL; m_num_lock_on = !!num_lock_value; - return KSuccess; + return {}; } case KEYBOARD_IOCTL_GET_CAPS_LOCK: { auto output = static_ptr_cast<bool*>(arg); @@ -330,7 +328,7 @@ KResult KeyboardDevice::ioctl(OpenFileDescription&, unsigned request, Userspace< if (caps_lock_value != 0 && caps_lock_value != 1) return EINVAL; m_caps_lock_on = !!caps_lock_value; - return KSuccess; + return {}; } default: return EINVAL; diff --git a/Kernel/Devices/HID/KeyboardDevice.h b/Kernel/Devices/HID/KeyboardDevice.h index 60c10c25fe..f5885aabb4 100644 --- a/Kernel/Devices/HID/KeyboardDevice.h +++ b/Kernel/Devices/HID/KeyboardDevice.h @@ -25,16 +25,16 @@ public: virtual ~KeyboardDevice() override; // ^CharacterDevice - virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override; + virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override; virtual bool can_read(const OpenFileDescription&, size_t) const override; - virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; } + virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; } virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; } // ^HIDDevice virtual Type instrument_type() const override { return Type::Keyboard; } // ^File - virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override; + virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override; void update_modifier(u8 modifier, bool state) { diff --git a/Kernel/Devices/HID/MouseDevice.cpp b/Kernel/Devices/HID/MouseDevice.cpp index 152ded7421..87441315fa 100644 --- a/Kernel/Devices/HID/MouseDevice.cpp +++ b/Kernel/Devices/HID/MouseDevice.cpp @@ -24,7 +24,7 @@ bool MouseDevice::can_read(const OpenFileDescription&, size_t) const return !m_queue.is_empty(); } -KResultOr<size_t> MouseDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size) +ErrorOr<size_t> MouseDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size) { VERIFY(size > 0); size_t nread = 0; diff --git a/Kernel/Devices/HID/MouseDevice.h b/Kernel/Devices/HID/MouseDevice.h index 41a939072d..e240c27cae 100644 --- a/Kernel/Devices/HID/MouseDevice.h +++ b/Kernel/Devices/HID/MouseDevice.h @@ -23,9 +23,9 @@ public: virtual ~MouseDevice() override; // ^CharacterDevice - virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override; + virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override; virtual bool can_read(const OpenFileDescription&, size_t) const override; - virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; } + virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; } virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; } // ^HIDDevice |