summaryrefslogtreecommitdiff
path: root/Kernel/Storage
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2023-04-11 00:47:52 +0300
committerLinus Groh <mail@linusgroh.de>2023-04-14 19:20:43 +0200
commit0050358cd331cc750570c53e6d544ced7cd52e41 (patch)
tree9af676732fa6bb9bb7aa963629f34b59095b4479 /Kernel/Storage
parentdac7e911e6afa316937f02e9686405347d4ddd0b (diff)
downloadserenity-0050358cd331cc750570c53e6d544ced7cd52e41.zip
Kernel/Storage: Modernize ATA IDE controller initialization code
This is done by 2 ways which both fit very well together: - We stop use LockRefPtrs. We also don't allow expansion of the m_channels member, by setting it to be a fixed Array of 2 IDEChannels. - More error propagation through the code, in the construction point of IDEChannel(s). This means that in the future we could technically do something meaningful with OOM conditions when initializing an IDE controller.
Diffstat (limited to 'Kernel/Storage')
-rw-r--r--Kernel/Storage/ATA/GenericIDE/Channel.cpp8
-rw-r--r--Kernel/Storage/ATA/GenericIDE/Channel.h4
-rw-r--r--Kernel/Storage/ATA/GenericIDE/Controller.h2
3 files changed, 7 insertions, 7 deletions
diff --git a/Kernel/Storage/ATA/GenericIDE/Channel.cpp b/Kernel/Storage/ATA/GenericIDE/Channel.cpp
index 35ff62cfda..9d41a2ba4c 100644
--- a/Kernel/Storage/ATA/GenericIDE/Channel.cpp
+++ b/Kernel/Storage/ATA/GenericIDE/Channel.cpp
@@ -24,16 +24,16 @@ namespace Kernel {
#define PATA_PRIMARY_IRQ 14
#define PATA_SECONDARY_IRQ 15
-UNMAP_AFTER_INIT NonnullLockRefPtr<IDEChannel> IDEChannel::create(IDEController const& controller, IOWindowGroup io_window_group, ChannelType type)
+UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<IDEChannel>> IDEChannel::create(IDEController const& controller, IOWindowGroup io_window_group, ChannelType type)
{
auto ata_identify_data_buffer = KBuffer::try_create_with_size("ATA Identify Page"sv, 4096, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value();
- return adopt_lock_ref(*new IDEChannel(controller, move(io_window_group), type, move(ata_identify_data_buffer)));
+ return adopt_nonnull_ref_or_enomem(new (nothrow) IDEChannel(controller, move(io_window_group), type, move(ata_identify_data_buffer)));
}
-UNMAP_AFTER_INIT NonnullLockRefPtr<IDEChannel> IDEChannel::create(IDEController const& controller, u8 irq, IOWindowGroup io_window_group, ChannelType type)
+UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<IDEChannel>> IDEChannel::create(IDEController const& controller, u8 irq, IOWindowGroup io_window_group, ChannelType type)
{
auto ata_identify_data_buffer = KBuffer::try_create_with_size("ATA Identify Page"sv, 4096, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value();
- return adopt_lock_ref(*new IDEChannel(controller, irq, move(io_window_group), type, move(ata_identify_data_buffer)));
+ return adopt_nonnull_ref_or_enomem(new (nothrow) IDEChannel(controller, irq, move(io_window_group), type, move(ata_identify_data_buffer)));
}
StringView IDEChannel::channel_type_string() const
diff --git a/Kernel/Storage/ATA/GenericIDE/Channel.h b/Kernel/Storage/ATA/GenericIDE/Channel.h
index f6b3d5829f..6eaa369e87 100644
--- a/Kernel/Storage/ATA/GenericIDE/Channel.h
+++ b/Kernel/Storage/ATA/GenericIDE/Channel.h
@@ -88,8 +88,8 @@ public:
};
public:
- static NonnullLockRefPtr<IDEChannel> create(IDEController const&, IOWindowGroup, ChannelType type);
- static NonnullLockRefPtr<IDEChannel> create(IDEController const&, u8 irq, IOWindowGroup, ChannelType type);
+ static ErrorOr<NonnullRefPtr<IDEChannel>> create(IDEController const&, IOWindowGroup, ChannelType type);
+ static ErrorOr<NonnullRefPtr<IDEChannel>> create(IDEController const&, u8 irq, IOWindowGroup, ChannelType type);
virtual ~IDEChannel() override;
diff --git a/Kernel/Storage/ATA/GenericIDE/Controller.h b/Kernel/Storage/ATA/GenericIDE/Controller.h
index 59ce472de2..56f6b378a1 100644
--- a/Kernel/Storage/ATA/GenericIDE/Controller.h
+++ b/Kernel/Storage/ATA/GenericIDE/Controller.h
@@ -31,6 +31,6 @@ protected:
IDEController();
LockRefPtr<StorageDevice> device_by_channel_and_position(u32 index) const;
- Vector<NonnullLockRefPtr<IDEChannel>> m_channels;
+ Array<RefPtr<IDEChannel>, 2> m_channels;
};
}