mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 19:54:57 +00:00
Kernel/USB: Use TRY() and adopt_nonnull_own_or_enomem() some more
This commit is contained in:
parent
e3b063581e
commit
f173f73f10
4 changed files with 5 additions and 20 deletions
|
@ -52,9 +52,7 @@ KResult SysFSUSBDeviceInformation::refresh_data(FileDescription& description) co
|
||||||
MutexLocker lock(m_lock);
|
MutexLocker lock(m_lock);
|
||||||
auto& cached_data = description.data();
|
auto& cached_data = description.data();
|
||||||
if (!cached_data) {
|
if (!cached_data) {
|
||||||
cached_data = adopt_own_if_nonnull(new (nothrow) SysFSInodeData);
|
cached_data = TRY(adopt_nonnull_own_or_enomem(new (nothrow) SysFSInodeData));
|
||||||
if (!cached_data)
|
|
||||||
return ENOMEM;
|
|
||||||
}
|
}
|
||||||
KBufferBuilder builder;
|
KBufferBuilder builder;
|
||||||
if (!const_cast<SysFSUSBDeviceInformation&>(*this).output(builder))
|
if (!const_cast<SysFSUSBDeviceInformation&>(*this).output(builder))
|
||||||
|
|
|
@ -85,11 +85,7 @@ static USBHubDescriptor uhci_root_hub_hub_descriptor = {
|
||||||
|
|
||||||
KResultOr<NonnullOwnPtr<UHCIRootHub>> UHCIRootHub::try_create(NonnullRefPtr<UHCIController> uhci_controller)
|
KResultOr<NonnullOwnPtr<UHCIRootHub>> UHCIRootHub::try_create(NonnullRefPtr<UHCIController> uhci_controller)
|
||||||
{
|
{
|
||||||
auto root_hub = adopt_own_if_nonnull(new (nothrow) UHCIRootHub(uhci_controller));
|
return adopt_nonnull_own_or_enomem(new (nothrow) UHCIRootHub(uhci_controller));
|
||||||
if (!root_hub)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
return root_hub.release_nonnull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UHCIRootHub::UHCIRootHub(NonnullRefPtr<UHCIController> uhci_controller)
|
UHCIRootHub::UHCIRootHub(NonnullRefPtr<UHCIController> uhci_controller)
|
||||||
|
|
|
@ -19,14 +19,9 @@ namespace Kernel::USB {
|
||||||
KResultOr<NonnullRefPtr<Device>> Device::try_create(USBController const& controller, u8 port, DeviceSpeed speed)
|
KResultOr<NonnullRefPtr<Device>> Device::try_create(USBController const& controller, u8 port, DeviceSpeed speed)
|
||||||
{
|
{
|
||||||
auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0));
|
auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0));
|
||||||
|
auto device = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Device(controller, port, speed, move(pipe))));
|
||||||
auto device = try_make_ref_counted<Device>(controller, port, speed, move(pipe));
|
|
||||||
if (!device)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
TRY(device->enumerate_device());
|
TRY(device->enumerate_device());
|
||||||
|
return device;
|
||||||
return device.release_nonnull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::Device(USBController const& controller, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe)
|
Device::Device(USBController const& controller, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe)
|
||||||
|
|
|
@ -13,11 +13,7 @@ namespace Kernel::USB {
|
||||||
|
|
||||||
KResultOr<NonnullOwnPtr<Pipe>> Pipe::try_create_pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval)
|
KResultOr<NonnullOwnPtr<Pipe>> Pipe::try_create_pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval)
|
||||||
{
|
{
|
||||||
auto pipe = adopt_own_if_nonnull(new (nothrow) Pipe(controller, type, direction, endpoint_address, max_packet_size, poll_interval, device_address));
|
return adopt_nonnull_own_or_enomem(new (nothrow) Pipe(controller, type, direction, endpoint_address, max_packet_size, poll_interval, device_address));
|
||||||
if (!pipe)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
return pipe.release_nonnull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipe::Pipe(USBController const& controller, Type type, Pipe::Direction direction, u16 max_packet_size)
|
Pipe::Pipe(USBController const& controller, Type type, Pipe::Direction direction, u16 max_packet_size)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue