1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:17:34 +00:00

Kernel: Use TRY() some more in USB::Hub

This commit is contained in:
Andreas Kling 2021-09-05 21:37:06 +02:00
parent 8ceff65161
commit 4d961387c1
2 changed files with 11 additions and 15 deletions

View file

@ -15,24 +15,18 @@ namespace Kernel::USB {
KResultOr<NonnullRefPtr<Hub>> Hub::try_create_root_hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed) 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. // NOTE: Enumeration does not happen here, as the controller must know what the device address is at all times during enumeration to intercept requests.
auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0));
return hub.release_nonnull(); 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) 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 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)); auto hub = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Hub(device, move(pipe))));
if (!hub)
return ENOMEM;
TRY(hub->enumerate_and_power_on_hub()); 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) Hub::Hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed, NonnullOwnPtr<Pipe> default_pipe)

View file

@ -83,9 +83,6 @@ public:
static KResultOr<NonnullRefPtr<Hub>> try_create_root_hub(NonnullRefPtr<USBController>, DeviceSpeed); static KResultOr<NonnullRefPtr<Hub>> try_create_root_hub(NonnullRefPtr<USBController>, DeviceSpeed);
static KResultOr<NonnullRefPtr<Hub>> try_create_from_device(Device const&); 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; virtual ~Hub() override = default;
KResult enumerate_and_power_on_hub(); KResult enumerate_and_power_on_hub();
@ -99,7 +96,12 @@ public:
void check_for_port_updates(); void check_for_port_updates();
private: 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; Device::List m_children;