Kernel/Storage: Use NonnullRefPtr for storage controllers

Storage controllers are initialized during init and are never modified.
NonnullRefPtr can be safely used instead of the NonnullLockRefPtr. This
also fixes one of the UB issue that was there when using an NVMe device
because of NonnullLockRefPtr.

We can add proper locking when we need to modify the storage controllers
after init.
This commit is contained in:
Pankaj Raghav 2023-03-14 09:44:21 +01:00 committed by Andreas Kling
parent 0dbca4af06
commit b204da94b0
11 changed files with 16 additions and 16 deletions

View file

@ -15,9 +15,9 @@
namespace Kernel {
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<ISAIDEController>> ISAIDEController::initialize()
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<ISAIDEController>> ISAIDEController::initialize()
{
auto controller = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) ISAIDEController()));
auto controller = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ISAIDEController()));
TRY(controller->initialize_channels());
return controller;
}

View file

@ -18,7 +18,7 @@ class AsyncBlockDeviceRequest;
class ISAIDEController final : public IDEController {
public:
static ErrorOr<NonnullLockRefPtr<ISAIDEController>> initialize();
static ErrorOr<NonnullRefPtr<ISAIDEController>> initialize();
private:
ISAIDEController();

View file

@ -15,9 +15,9 @@
namespace Kernel {
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<PCIIDELegacyModeController>> PCIIDELegacyModeController::initialize(PCI::DeviceIdentifier const& device_identifier, bool force_pio)
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<PCIIDELegacyModeController>> PCIIDELegacyModeController::initialize(PCI::DeviceIdentifier const& device_identifier, bool force_pio)
{
auto controller = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) PCIIDELegacyModeController(device_identifier)));
auto controller = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) PCIIDELegacyModeController(device_identifier)));
PCI::enable_io_space(device_identifier);
PCI::enable_memory_space(device_identifier);
PCI::enable_bus_mastering(device_identifier);

View file

@ -19,7 +19,7 @@ class AsyncBlockDeviceRequest;
class PCIIDELegacyModeController final : public IDEController
, public PCI::Device {
public:
static ErrorOr<NonnullLockRefPtr<PCIIDELegacyModeController>> initialize(PCI::DeviceIdentifier const&, bool force_pio);
static ErrorOr<NonnullRefPtr<PCIIDELegacyModeController>> initialize(PCI::DeviceIdentifier const&, bool force_pio);
virtual StringView device_name() const override { return "PCIIDELegacyModeController"sv; }

View file

@ -18,9 +18,9 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullLockRefPtr<AHCIController> AHCIController::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
UNMAP_AFTER_INIT NonnullRefPtr<AHCIController> AHCIController::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
{
auto controller = adopt_lock_ref_if_nonnull(new (nothrow) AHCIController(pci_device_identifier)).release_nonnull();
auto controller = adopt_ref_if_nonnull(new (nothrow) AHCIController(pci_device_identifier)).release_nonnull();
controller->initialize_hba(pci_device_identifier);
return controller;
}

View file

@ -24,7 +24,7 @@ class AHCIController final : public ATAController
friend class AHCIInterruptHandler;
public:
static NonnullLockRefPtr<AHCIController> initialize(PCI::DeviceIdentifier const& pci_device_identifier);
static NonnullRefPtr<AHCIController> initialize(PCI::DeviceIdentifier const& pci_device_identifier);
virtual ~AHCIController() override;
virtual StringView device_name() const override { return "AHCI"sv; }

View file

@ -19,9 +19,9 @@
namespace Kernel {
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<NVMeController>> NVMeController::try_initialize(Kernel::PCI::DeviceIdentifier const& device_identifier, bool is_queue_polled)
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<NVMeController>> NVMeController::try_initialize(Kernel::PCI::DeviceIdentifier const& device_identifier, bool is_queue_polled)
{
auto controller = TRY(adopt_nonnull_lock_ref_or_enomem(new NVMeController(device_identifier, StorageManagement::generate_relative_nvme_controller_id({}))));
auto controller = TRY(adopt_nonnull_ref_or_enomem(new NVMeController(device_identifier, StorageManagement::generate_relative_nvme_controller_id({}))));
TRY(controller->initialize(is_queue_polled));
return controller;
}

View file

@ -25,7 +25,7 @@ namespace Kernel {
class NVMeController : public PCI::Device
, public StorageController {
public:
static ErrorOr<NonnullLockRefPtr<NVMeController>> try_initialize(PCI::DeviceIdentifier const&, bool is_queue_polled);
static ErrorOr<NonnullRefPtr<NVMeController>> try_initialize(PCI::DeviceIdentifier const&, bool is_queue_polled);
ErrorOr<void> initialize(bool is_queue_polled);
LockRefPtr<StorageDevice> device(u32 index) const override;
size_t devices_count() const override;

View file

@ -11,9 +11,9 @@
namespace Kernel {
NonnullLockRefPtr<RamdiskController> RamdiskController::initialize()
NonnullRefPtr<RamdiskController> RamdiskController::initialize()
{
return adopt_lock_ref(*new RamdiskController());
return adopt_ref(*new RamdiskController());
}
bool RamdiskController::reset()

View file

@ -19,7 +19,7 @@ class AsyncBlockDeviceRequest;
class RamdiskController final : public StorageController {
public:
static NonnullLockRefPtr<RamdiskController> initialize();
static NonnullRefPtr<RamdiskController> initialize();
virtual ~RamdiskController() override;
virtual LockRefPtr<StorageDevice> device(u32 index) const override;

View file

@ -66,7 +66,7 @@ private:
StringView m_boot_argument;
LockWeakPtr<BlockDevice> m_boot_block_device;
Vector<NonnullLockRefPtr<StorageController>> m_controllers;
Vector<NonnullRefPtr<StorageController>> m_controllers;
IntrusiveList<&StorageDevice::m_list_node> m_storage_devices;
};