From 7b745a20f17a4212debd153f66337980b93e830b Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 7 Apr 2023 14:49:49 +0300 Subject: [PATCH] Kernel: Mark a bunch of NonnullRefPtrs also const to ensure immutability These were easy to pick-up as these pointers are assigned during the construction point and are never changed afterwards. This small change to these pointers will ensure that our code will not accidentally assign these pointers with a new object which is always a kind of bug we will want to prevent. --- Kernel/Bus/PCI/Device.h | 2 +- Kernel/Coredump.h | 2 +- Kernel/FileSystem/Custody.h | 2 +- Kernel/FileSystem/FileBackedFileSystem.h | 2 +- Kernel/FileSystem/InodeFile.h | 2 +- Kernel/FileSystem/OpenFileDescription.h | 2 +- Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h | 2 +- Kernel/Jail.h | 2 +- Kernel/Memory/InodeVMObject.h | 2 +- Kernel/Storage/ATA/AHCI/Port.h | 2 +- Kernel/Storage/NVMe/NVMeQueue.h | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Kernel/Bus/PCI/Device.h b/Kernel/Bus/PCI/Device.h index 58a47f0657..1f6a22877e 100644 --- a/Kernel/Bus/PCI/Device.h +++ b/Kernel/Bus/PCI/Device.h @@ -38,7 +38,7 @@ protected: explicit Device(DeviceIdentifier const& pci_identifier); private: - NonnullRefPtr m_pci_identifier; + NonnullRefPtr const m_pci_identifier; }; template diff --git a/Kernel/Coredump.h b/Kernel/Coredump.h index 79873a1cc0..dbe5968ef8 100644 --- a/Kernel/Coredump.h +++ b/Kernel/Coredump.h @@ -80,7 +80,7 @@ private: ErrorOr create_notes_metadata_data(auto&) const; NonnullRefPtr const m_process; - NonnullRefPtr m_description; + NonnullRefPtr const m_description; size_t m_num_program_headers { 0 }; Vector m_regions; }; diff --git a/Kernel/FileSystem/Custody.h b/Kernel/FileSystem/Custody.h index 6bd9a0902e..5abed86fe9 100644 --- a/Kernel/FileSystem/Custody.h +++ b/Kernel/FileSystem/Custody.h @@ -37,7 +37,7 @@ private: RefPtr m_parent; NonnullOwnPtr m_name; - NonnullRefPtr m_inode; + NonnullRefPtr const m_inode; int m_mount_flags { 0 }; mutable IntrusiveListNode m_all_custodies_list_node; diff --git a/Kernel/FileSystem/FileBackedFileSystem.h b/Kernel/FileSystem/FileBackedFileSystem.h index 57ae426a81..254a4e860e 100644 --- a/Kernel/FileSystem/FileBackedFileSystem.h +++ b/Kernel/FileSystem/FileBackedFileSystem.h @@ -38,6 +38,6 @@ private: virtual bool is_file_backed() const override { return true; } IntrusiveListNode m_file_backed_file_system_node; - NonnullRefPtr m_file_description; + NonnullRefPtr const m_file_description; }; } diff --git a/Kernel/FileSystem/InodeFile.h b/Kernel/FileSystem/InodeFile.h index 9ece2206d4..dc94da0eb4 100644 --- a/Kernel/FileSystem/InodeFile.h +++ b/Kernel/FileSystem/InodeFile.h @@ -52,7 +52,7 @@ private: virtual bool is_regular_file() const override; explicit InodeFile(NonnullRefPtr); - NonnullRefPtr m_inode; + NonnullRefPtr const m_inode; }; } diff --git a/Kernel/FileSystem/OpenFileDescription.h b/Kernel/FileSystem/OpenFileDescription.h index 056398143b..ca857c9525 100644 --- a/Kernel/FileSystem/OpenFileDescription.h +++ b/Kernel/FileSystem/OpenFileDescription.h @@ -141,7 +141,7 @@ private: } RefPtr m_inode; - NonnullRefPtr m_file; + NonnullRefPtr const m_file; struct State { OwnPtr data; diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h index 05042fb754..a5603b26c1 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h @@ -23,7 +23,7 @@ public: private: PCIDeviceSysFSDirectory(NonnullOwnPtr device_directory_name, SysFSDirectory const&, PCI::DeviceIdentifier const&); - NonnullRefPtr m_device_identifier; + NonnullRefPtr const m_device_identifier; NonnullOwnPtr m_device_directory_name; }; diff --git a/Kernel/Jail.h b/Kernel/Jail.h index 2e9985762c..cc4313e85e 100644 --- a/Kernel/Jail.h +++ b/Kernel/Jail.h @@ -52,7 +52,7 @@ public: using List = IntrusiveListRelaxedConst<&Jail::m_list_node>; private: - NonnullRefPtr m_process_list; + NonnullRefPtr const m_process_list; SpinlockProtected m_attach_count { 0 }; }; diff --git a/Kernel/Memory/InodeVMObject.h b/Kernel/Memory/InodeVMObject.h index 182e24e26a..ebd087ae59 100644 --- a/Kernel/Memory/InodeVMObject.h +++ b/Kernel/Memory/InodeVMObject.h @@ -37,7 +37,7 @@ protected: virtual bool is_inode() const final { return true; } - NonnullRefPtr m_inode; + NonnullRefPtr const m_inode; Bitmap m_dirty_pages; }; diff --git a/Kernel/Storage/ATA/AHCI/Port.h b/Kernel/Storage/ATA/AHCI/Port.h index 6b501bf26b..8818d36190 100644 --- a/Kernel/Storage/ATA/AHCI/Port.h +++ b/Kernel/Storage/ATA/AHCI/Port.h @@ -123,7 +123,7 @@ private: // it's probably better to just "cache" this here instead. AHCI::HBADefinedCapabilities const m_hba_capabilities; - NonnullRefPtr m_identify_buffer_page; + NonnullRefPtr const m_identify_buffer_page; volatile AHCI::PortRegisters& m_port_registers; LockWeakPtr m_parent_controller; diff --git a/Kernel/Storage/NVMe/NVMeQueue.h b/Kernel/Storage/NVMe/NVMeQueue.h index 2dd9cb73fc..eac56407eb 100644 --- a/Kernel/Storage/NVMe/NVMeQueue.h +++ b/Kernel/Storage/NVMe/NVMeQueue.h @@ -97,6 +97,6 @@ private: Span m_cqe_array; WaitQueue m_sync_wait_queue; Memory::TypedMapping m_db_regs; - NonnullRefPtr m_rw_dma_page; + NonnullRefPtr const m_rw_dma_page; }; }