1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

Kernel/USB: Replace PortNumber enum with a raw u8

A hub can technically have up to 255 ports, given that bNbrPorts is a
u8 and the DeviceRemovable field is a VLA to support up to 255 ports.

Source: USB 2.0 Specification Section 11.23.2.1

That means this enum is not going to scale well in terms of size.
Replacing it with a raw u8 allows me to remove the two port assumption
and a cast.
This commit is contained in:
Luke 2021-08-14 00:20:53 +01:00 committed by Andreas Kling
parent 86ccacf6b5
commit b6a2bbba3b
3 changed files with 11 additions and 18 deletions

View file

@ -45,7 +45,7 @@ KResultOr<NonnullRefPtr<Hub>> Hub::try_create_from_device(Device const& device)
}
Hub::Hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed, NonnullOwnPtr<Pipe> default_pipe)
: Device(move(controller), PortNumber::Port1, device_speed, move(default_pipe))
: Device(move(controller), 1 /* Port 1 */, device_speed, move(default_pipe))
{
}
@ -260,8 +260,7 @@ void Hub::check_for_port_updates()
// FIXME: Check for high speed.
auto speed = port_status.status & PORT_STATUS_LOW_SPEED_DEVICE_ATTACHED ? USB::Device::DeviceSpeed::LowSpeed : USB::Device::DeviceSpeed::FullSpeed;
// FIXME: This only assumes two ports.
auto device_or_error = USB::Device::try_create(m_controller, port_number == 1 ? PortNumber::Port1 : PortNumber::Port2, speed);
auto device_or_error = USB::Device::try_create(m_controller, port_number, speed);
if (device_or_error.is_error()) {
dbgln("USB Hub: Failed to create device for port {}: {}", port_number, device_or_error.error());
return;
@ -290,8 +289,7 @@ void Hub::check_for_port_updates()
Device* device_to_remove = nullptr;
for (auto& child : m_children) {
// FIXME: This kinda sucks.
if (port_number - 1 == (u8)child.port()) {
if (port_number == child.port()) {
device_to_remove = &child;
break;
}