diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-20 23:11:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-20 23:20:02 +0100 |
commit | 19d3f8cab77a95b284e30f142521c6b483221324 (patch) | |
tree | 8df3f585e91113215b52d10a9a0032c9998dc1b5 /Kernel/Devices | |
parent | e279b45aed5509efc537fc8c831f40733d7b1028 (diff) | |
download | serenity-19d3f8cab77a95b284e30f142521c6b483221324.zip |
Kernel+LibC: Turn errno codes into a strongly typed enum
..and allow implicit creation of KResult and KResultOr from ErrnoCode.
This means that kernel functions that return those types can finally
do "return EINVAL;" and it will just work.
There's a handful of functions that still deal with signed integers
that should be converted to return KResults.
Diffstat (limited to 'Kernel/Devices')
-rw-r--r-- | Kernel/Devices/BXVGADevice.cpp | 4 | ||||
-rw-r--r-- | Kernel/Devices/FullDevice.cpp | 4 | ||||
-rw-r--r-- | Kernel/Devices/KeyboardDevice.cpp | 2 | ||||
-rw-r--r-- | Kernel/Devices/MBVGADevice.cpp | 4 | ||||
-rw-r--r-- | Kernel/Devices/PS2MouseDevice.cpp | 2 | ||||
-rw-r--r-- | Kernel/Devices/RandomDevice.cpp | 2 | ||||
-rw-r--r-- | Kernel/Devices/SB16.cpp | 8 | ||||
-rw-r--r-- | Kernel/Devices/SerialDevice.cpp | 4 | ||||
-rw-r--r-- | Kernel/Devices/ZeroDevice.cpp | 2 |
9 files changed, 16 insertions, 16 deletions
diff --git a/Kernel/Devices/BXVGADevice.cpp b/Kernel/Devices/BXVGADevice.cpp index 44afeb24b1..034922f373 100644 --- a/Kernel/Devices/BXVGADevice.cpp +++ b/Kernel/Devices/BXVGADevice.cpp @@ -179,12 +179,12 @@ KResultOr<Region*> BXVGADevice::mmap(Process& process, FileDescription&, Virtual { REQUIRE_PROMISE(video); if (!shared) - return KResult(-ENODEV); + return ENODEV; ASSERT(offset == 0); ASSERT(size == framebuffer_size_in_bytes()); auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes()); if (!vmobject) - return KResult(-ENOMEM); + return ENOMEM; return process.allocate_region_with_vmobject( preferred_vaddr, framebuffer_size_in_bytes(), diff --git a/Kernel/Devices/FullDevice.cpp b/Kernel/Devices/FullDevice.cpp index 0d43d7a950..cbe5ca0d1d 100644 --- a/Kernel/Devices/FullDevice.cpp +++ b/Kernel/Devices/FullDevice.cpp @@ -50,7 +50,7 @@ KResultOr<size_t> FullDevice::read(FileDescription&, size_t, UserOrKernelBuffer& { ssize_t count = min(static_cast<size_t>(PAGE_SIZE), size); if (!buffer.memset(0, count)) - return KResult(-EFAULT); + return EFAULT; return count; } @@ -58,7 +58,7 @@ KResultOr<size_t> FullDevice::write(FileDescription&, size_t, const UserOrKernel { if (size == 0) return 0; - return KResult(-ENOSPC); + return ENOSPC; } } diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index d6974aaa27..2c244b1794 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -386,7 +386,7 @@ KResultOr<size_t> KeyboardDevice::read(FileDescription&, size_t, UserOrKernelBuf return (ssize_t)data_bytes; }); if (n < 0) - return KResult(n); + return KResult((ErrnoCode)-n); ASSERT((size_t)n == sizeof(Event)); nread += sizeof(Event); diff --git a/Kernel/Devices/MBVGADevice.cpp b/Kernel/Devices/MBVGADevice.cpp index 3ae439a689..38ee00f047 100644 --- a/Kernel/Devices/MBVGADevice.cpp +++ b/Kernel/Devices/MBVGADevice.cpp @@ -55,12 +55,12 @@ KResultOr<Region*> MBVGADevice::mmap(Process& process, FileDescription&, Virtual { REQUIRE_PROMISE(video); if (!shared) - return KResult(-ENODEV); + return ENODEV; ASSERT(offset == 0); ASSERT(size == framebuffer_size_in_bytes()); auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes()); if (!vmobject) - return KResult(-ENOMEM); + return ENOMEM; return process.allocate_region_with_vmobject( preferred_vaddr, framebuffer_size_in_bytes(), diff --git a/Kernel/Devices/PS2MouseDevice.cpp b/Kernel/Devices/PS2MouseDevice.cpp index ee53c540a6..89d42c39b4 100644 --- a/Kernel/Devices/PS2MouseDevice.cpp +++ b/Kernel/Devices/PS2MouseDevice.cpp @@ -288,7 +288,7 @@ KResultOr<size_t> PS2MouseDevice::read(FileDescription&, size_t, UserOrKernelBuf #endif size_t bytes_read_from_packet = min(remaining_space_in_buffer, sizeof(MousePacket)); if (!buffer.write(&packet, nread, bytes_read_from_packet)) - return KResult(-EFAULT); + return EFAULT; nread += bytes_read_from_packet; remaining_space_in_buffer -= bytes_read_from_packet; diff --git a/Kernel/Devices/RandomDevice.cpp b/Kernel/Devices/RandomDevice.cpp index fa625d0ecf..728e5456b4 100644 --- a/Kernel/Devices/RandomDevice.cpp +++ b/Kernel/Devices/RandomDevice.cpp @@ -50,7 +50,7 @@ KResultOr<size_t> RandomDevice::read(FileDescription&, size_t, UserOrKernelBuffe return (ssize_t)data_size; }); if (!success) - return KResult(-EFAULT); + return EFAULT; return size; } diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp index c0430c7259..c9d1abb7c5 100644 --- a/Kernel/Devices/SB16.cpp +++ b/Kernel/Devices/SB16.cpp @@ -236,11 +236,11 @@ KResultOr<size_t> SB16::write(FileDescription&, size_t, const UserOrKernelBuffer if (!m_dma_region) { auto page = MM.allocate_supervisor_physical_page(); if (!page) - return KResult(-ENOMEM); + return ENOMEM; auto vmobject = AnonymousVMObject::create_with_physical_page(*page); m_dma_region = MM.allocate_kernel_region_with_vmobject(*vmobject, PAGE_SIZE, "SB16 DMA buffer", Region::Access::Write); if (!m_dma_region) - return KResult(-ENOMEM); + return ENOMEM; } #ifdef SB16_DEBUG @@ -249,7 +249,7 @@ KResultOr<size_t> SB16::write(FileDescription&, size_t, const UserOrKernelBuffer ASSERT(length <= PAGE_SIZE); const int BLOCK_SIZE = 32 * 1024; if (length > BLOCK_SIZE) { - return KResult(-ENOSPC); + return ENOSPC; } u8 mode = (u8)SampleFormat::Signed | (u8)SampleFormat::Stereo; @@ -257,7 +257,7 @@ KResultOr<size_t> SB16::write(FileDescription&, size_t, const UserOrKernelBuffer const int sample_rate = 44100; set_sample_rate(sample_rate); if (!data.read(m_dma_region->vaddr().as_ptr(), length)) - return KResult(-EFAULT); + return EFAULT; dma_start(length); // 16-bit single-cycle output. diff --git a/Kernel/Devices/SerialDevice.cpp b/Kernel/Devices/SerialDevice.cpp index a54a8bed3e..9801c6b83d 100644 --- a/Kernel/Devices/SerialDevice.cpp +++ b/Kernel/Devices/SerialDevice.cpp @@ -59,7 +59,7 @@ KResultOr<size_t> SerialDevice::read(FileDescription&, size_t, UserOrKernelBuffe return (ssize_t)data_size; }); if (nwritten < 0) - return KResult(nwritten); + return KResult((ErrnoCode)-nwritten); return size; } @@ -83,7 +83,7 @@ KResultOr<size_t> SerialDevice::write(FileDescription&, size_t, const UserOrKern return (ssize_t)data_size; }); if (nread < 0) - return KResult(nread); + return KResult((ErrnoCode)-nread); return (size_t)nread; } diff --git a/Kernel/Devices/ZeroDevice.cpp b/Kernel/Devices/ZeroDevice.cpp index ac326434d0..f0b0302f64 100644 --- a/Kernel/Devices/ZeroDevice.cpp +++ b/Kernel/Devices/ZeroDevice.cpp @@ -48,7 +48,7 @@ KResultOr<size_t> ZeroDevice::read(FileDescription&, size_t, UserOrKernelBuffer& { ssize_t count = min(static_cast<size_t>(PAGE_SIZE), size); if (!buffer.memset(0, count)) - return KResult(-EFAULT); + return EFAULT; return count; } |