mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
Kernel/VirtIO: Don't expose constructors as public method
This leads to a bad pattern where anyone could create an RNG or a Console object. Instead, let's just use the common pattern of a static method to instantiate a new object and return it wrapped by a NonnullRefPtr.
This commit is contained in:
parent
01ae614727
commit
8e90a4fd1c
5 changed files with 16 additions and 5 deletions
|
@ -12,6 +12,11 @@ namespace Kernel::VirtIO {
|
|||
|
||||
unsigned Console::next_device_id = 0;
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<Console> Console::must_create(PCI::Address address)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new Console(address)).release_nonnull();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT Console::Console(PCI::Address address)
|
||||
: VirtIO::Device(address)
|
||||
, m_device_id(next_device_id++)
|
||||
|
|
|
@ -18,7 +18,7 @@ class Console
|
|||
friend VirtIO::ConsolePort;
|
||||
|
||||
public:
|
||||
Console(PCI::Address);
|
||||
static NonnullRefPtr<Console> must_create(PCI::Address address);
|
||||
virtual ~Console() override = default;
|
||||
|
||||
virtual StringView purpose() const override { return class_name(); }
|
||||
|
@ -30,6 +30,7 @@ public:
|
|||
|
||||
private:
|
||||
virtual StringView class_name() const override { return "VirtIOConsole"; }
|
||||
explicit Console(PCI::Address);
|
||||
enum class ControlEvent : u16 {
|
||||
DeviceReady = 0,
|
||||
DeviceAdd = 1,
|
||||
|
|
|
@ -25,11 +25,11 @@ UNMAP_AFTER_INIT void detect()
|
|||
return;
|
||||
switch (id.device_id) {
|
||||
case PCI::DeviceID::VirtIOConsole: {
|
||||
[[maybe_unused]] auto& unused = adopt_ref(*new Console(address)).leak_ref();
|
||||
[[maybe_unused]] auto& unused = Console::must_create(address).leak_ref();
|
||||
break;
|
||||
}
|
||||
case PCI::DeviceID::VirtIOEntropy: {
|
||||
[[maybe_unused]] auto& unused = adopt_ref(*new RNG(address)).leak_ref();
|
||||
[[maybe_unused]] auto& unused = RNG::must_create(address).leak_ref();
|
||||
break;
|
||||
}
|
||||
case PCI::DeviceID::VirtIOGPU: {
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
|
||||
namespace Kernel::VirtIO {
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<RNG> RNG::must_create(PCI::Address address)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new RNG(address)).release_nonnull();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT RNG::RNG(PCI::Address address)
|
||||
: VirtIO::Device(address)
|
||||
{
|
||||
|
|
|
@ -19,13 +19,13 @@ class RNG final
|
|||
: public RefCounted<RNG>
|
||||
, public VirtIO::Device {
|
||||
public:
|
||||
static NonnullRefPtr<RNG> must_create(PCI::Address address);
|
||||
virtual StringView purpose() const override { return class_name(); }
|
||||
|
||||
RNG(PCI::Address);
|
||||
virtual ~RNG() override;
|
||||
|
||||
private:
|
||||
virtual StringView class_name() const override { return "VirtIOConsole"; }
|
||||
explicit RNG(PCI::Address);
|
||||
virtual bool handle_device_config_change() override;
|
||||
virtual void handle_queue_update(u16 queue_index) override;
|
||||
void request_entropy_from_host();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue