summaryrefslogtreecommitdiff
path: root/Kernel/Storage
diff options
context:
space:
mode:
authorPankaj Raghav <p.raghav@samsung.com>2023-03-14 10:24:27 +0100
committerAndreas Kling <kling@serenityos.org>2023-03-15 11:25:59 +0100
commit6ff85aa19ad7642ea0a099ab8bfa161de95157ce (patch)
treeb1029da1d565361f4deb4b8cf836a2eaccca73d5 /Kernel/Storage
parentb204da94b09fcb915319fff490045117bebc0078 (diff)
downloadserenity-6ff85aa19ad7642ea0a099ab8bfa161de95157ce.zip
Kernel/Ramdisk: Propagate error during Ramdisk initialize
Use the same pattern for Ramdisk similar to other storage devices during device initialization. This will propagate errors if the Ramdisk fails to initialize.
Diffstat (limited to 'Kernel/Storage')
-rw-r--r--Kernel/Storage/Ramdisk/Controller.cpp4
-rw-r--r--Kernel/Storage/Ramdisk/Controller.h2
-rw-r--r--Kernel/Storage/StorageManagement.cpp7
3 files changed, 9 insertions, 4 deletions
diff --git a/Kernel/Storage/Ramdisk/Controller.cpp b/Kernel/Storage/Ramdisk/Controller.cpp
index 2893c737db..d414b0ca28 100644
--- a/Kernel/Storage/Ramdisk/Controller.cpp
+++ b/Kernel/Storage/Ramdisk/Controller.cpp
@@ -11,9 +11,9 @@
namespace Kernel {
-NonnullRefPtr<RamdiskController> RamdiskController::initialize()
+ErrorOr<NonnullRefPtr<RamdiskController>> RamdiskController::try_initialize()
{
- return adopt_ref(*new RamdiskController());
+ return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) RamdiskController()));
}
bool RamdiskController::reset()
diff --git a/Kernel/Storage/Ramdisk/Controller.h b/Kernel/Storage/Ramdisk/Controller.h
index 4a92dce5a4..7f345990bf 100644
--- a/Kernel/Storage/Ramdisk/Controller.h
+++ b/Kernel/Storage/Ramdisk/Controller.h
@@ -19,7 +19,7 @@ class AsyncBlockDeviceRequest;
class RamdiskController final : public StorageController {
public:
- static NonnullRefPtr<RamdiskController> initialize();
+ static ErrorOr<NonnullRefPtr<RamdiskController>> try_initialize();
virtual ~RamdiskController() override;
virtual LockRefPtr<StorageDevice> device(u32 index) const override;
diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp
index 7fa774d8d2..76dd7fd826 100644
--- a/Kernel/Storage/StorageManagement.cpp
+++ b/Kernel/Storage/StorageManagement.cpp
@@ -444,7 +444,12 @@ UNMAP_AFTER_INIT void StorageManagement::initialize(StringView root_device, bool
}
// Note: Whether PCI bus is present on the system or not, always try to attach
// a given ramdisk.
- m_controllers.append(RamdiskController::initialize());
+ auto controller = RamdiskController::try_initialize();
+ if (controller.is_error()) {
+ dmesgln("Unable to initialize RAM controller: {}", controller.error());
+ } else {
+ m_controllers.append(controller.release_value());
+ }
enumerate_storage_devices();
enumerate_disk_partitions();