1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +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:
Liav A 2021-08-27 12:32:05 +03:00 committed by Andreas Kling
parent 01ae614727
commit 8e90a4fd1c
5 changed files with 16 additions and 5 deletions

View file

@ -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: {