diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-05 21:37:06 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-06 01:55:27 +0200 |
commit | 4d961387c1fcdd05120f99c6cd0642ee5726fd4a (patch) | |
tree | 739b987cdbb3f4783190eae68216d302136c62ad /Kernel | |
parent | 8ceff6516152e63209073426a947f8937a6f1a00 (diff) | |
download | serenity-4d961387c1fcdd05120f99c6cd0642ee5726fd4a.zip |
Kernel: Use TRY() some more in USB::Hub
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Bus/USB/USBHub.cpp | 16 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBHub.h | 10 |
2 files changed, 11 insertions, 15 deletions
diff --git a/Kernel/Bus/USB/USBHub.cpp b/Kernel/Bus/USB/USBHub.cpp index 7acea2d8da..a6c958363d 100644 --- a/Kernel/Bus/USB/USBHub.cpp +++ b/Kernel/Bus/USB/USBHub.cpp @@ -15,24 +15,18 @@ namespace Kernel::USB { KResultOr<NonnullRefPtr<Hub>> Hub::try_create_root_hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed) { - auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0)); - auto hub = try_make_ref_counted<Hub>(controller, device_speed, move(pipe)); - if (!hub) - return ENOMEM; - // NOTE: Enumeration does not happen here, as the controller must know what the device address is at all times during enumeration to intercept requests. - - return hub.release_nonnull(); + auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0)); + auto hub = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Hub(controller, device_speed, move(pipe)))); + return hub; } KResultOr<NonnullRefPtr<Hub>> Hub::try_create_from_device(Device const& device) { auto pipe = TRY(Pipe::try_create_pipe(device.controller(), Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, device.device_descriptor().max_packet_size, device.address())); - auto hub = try_make_ref_counted<Hub>(device, move(pipe)); - if (!hub) - return ENOMEM; + auto hub = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Hub(device, move(pipe)))); TRY(hub->enumerate_and_power_on_hub()); - return hub.release_nonnull(); + return hub; } Hub::Hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed, NonnullOwnPtr<Pipe> default_pipe) diff --git a/Kernel/Bus/USB/USBHub.h b/Kernel/Bus/USB/USBHub.h index 3ae22489cb..35529df67e 100644 --- a/Kernel/Bus/USB/USBHub.h +++ b/Kernel/Bus/USB/USBHub.h @@ -83,9 +83,6 @@ public: static KResultOr<NonnullRefPtr<Hub>> try_create_root_hub(NonnullRefPtr<USBController>, DeviceSpeed); static KResultOr<NonnullRefPtr<Hub>> try_create_from_device(Device const&); - // Root Hub constructor - Hub(NonnullRefPtr<USBController>, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe); - Hub(Device const&, NonnullOwnPtr<Pipe> default_pipe); virtual ~Hub() override = default; KResult enumerate_and_power_on_hub(); @@ -99,7 +96,12 @@ public: void check_for_port_updates(); private: - USBHubDescriptor m_hub_descriptor; + // Root Hub constructor + Hub(NonnullRefPtr<USBController>, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe); + + Hub(Device const&, NonnullOwnPtr<Pipe> default_pipe); + + USBHubDescriptor m_hub_descriptor {}; Device::List m_children; |