Kernel: Get rid of *LockRefPtr in the SysFS filesystem code

To do this we also need to get rid of LockRefPtrs in the USB code as
well.
Most of the SysFS nodes are statically generated during boot and are not
mutated afterwards.

The same goes for general device code - once we generate the appropriate
SysFS nodes, we almost never mutate the node pointers afterwards, making
locking unnecessary.
This commit is contained in:
Liav A 2023-04-05 13:21:11 +03:00 committed by Linus Groh
parent dd7633c5f4
commit b02ee664e7
Notes: sideshowbarker 2024-07-17 06:45:52 +09:00
114 changed files with 230 additions and 218 deletions

View file

@ -46,7 +46,10 @@ ErrorOr<void> Hub::enumerate_and_power_on_hub()
// USBDevice::enumerate_device must be called before this.
VERIFY(m_address > 0);
m_sysfs_device_info_node = TRY(SysFSUSBDeviceInformation::create(*this));
TRY(m_sysfs_device_info_node.with([&](auto& node) -> ErrorOr<void> {
node = TRY(SysFSUSBDeviceInformation::create(*this));
return {};
}));
if (m_device_descriptor.device_class != USB_CLASS_HUB) {
dbgln("USB Hub: Trying to enumerate and power on a device that says it isn't a hub.");
@ -133,8 +136,11 @@ ErrorOr<void> Hub::set_port_feature(u8 port, HubFeatureSelector feature_selector
void Hub::remove_children_from_sysfs()
{
for (auto& child : m_children)
SysFSUSBBusDirectory::the().unplug({}, child.sysfs_device_info_node({}));
for (auto& child : m_children) {
child.sysfs_device_info_node({}).with([](auto& node) {
SysFSUSBBusDirectory::the().unplug({}, *node);
});
}
}
void Hub::check_for_port_updates()
@ -260,10 +266,14 @@ void Hub::check_for_port_updates()
auto hub = hub_or_error.release_value();
m_children.append(hub);
SysFSUSBBusDirectory::the().plug({}, hub->sysfs_device_info_node({}));
hub->sysfs_device_info_node({}).with([](auto& node) {
SysFSUSBBusDirectory::the().plug({}, *node);
});
} else {
m_children.append(device);
SysFSUSBBusDirectory::the().plug({}, device->sysfs_device_info_node({}));
device->sysfs_device_info_node({}).with([](auto& node) {
SysFSUSBBusDirectory::the().plug({}, *node);
});
}
} else {
@ -278,7 +288,9 @@ void Hub::check_for_port_updates()
}
if (device_to_remove) {
SysFSUSBBusDirectory::the().unplug({}, device_to_remove->sysfs_device_info_node({}));
device_to_remove->sysfs_device_info_node({}).with([](auto& node) {
SysFSUSBBusDirectory::the().unplug({}, *node);
});
if (device_to_remove->device_descriptor().device_class == USB_CLASS_HUB) {
auto* hub_child = static_cast<Hub*>(device_to_remove.ptr());
hub_child->remove_children_from_sysfs();