diff options
author | Liav A <liavalb@gmail.com> | 2022-04-23 09:45:31 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-15 12:29:23 +0200 |
commit | cdab213750769db79e85a7d78591bc867e603928 (patch) | |
tree | 1287d4cea671e05098cd1aa09cdd1c2925ad8822 /Kernel/FileSystem/SysFS | |
parent | 70afa0b171af5396855c6e156fd25063845d44bd (diff) | |
download | serenity-cdab213750769db79e85a7d78591bc867e603928.zip |
Kernel/SysFS: Adapt USB plug code to work with SysFS patterns
Diffstat (limited to 'Kernel/FileSystem/SysFS')
3 files changed, 18 insertions, 41 deletions
diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.cpp b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.cpp index 4f31888a87..11863b07ea 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.cpp @@ -10,44 +10,27 @@ namespace Kernel { -static SysFSUSBBusDirectory* s_procfs_usb_bus_directory; +static SysFSUSBBusDirectory* s_sysfs_usb_bus_directory; -RefPtr<SysFSUSBDeviceInformation> SysFSUSBBusDirectory::device_node_for(USB::Device& device) +void SysFSUSBBusDirectory::plug(Badge<USB::Hub>, SysFSUSBDeviceInformation& new_device_info_node) { - RefPtr<USB::Device> checked_device = device; - for (auto& device_node : m_device_nodes) { - if (device_node.device().ptr() == checked_device.ptr()) - return device_node; - } - return {}; + MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> { + list.append(new_device_info_node); + return {}; + })); } - -void SysFSUSBBusDirectory::plug(USB::Device& new_device) -{ - SpinlockLocker lock(m_lock); - auto device_node = device_node_for(new_device); - VERIFY(!device_node); - auto sysfs_usb_device_or_error = SysFSUSBDeviceInformation::create(new_device); - if (sysfs_usb_device_or_error.is_error()) { - dbgln("Failed to create SysFSUSBDevice for device id {}", new_device.address()); - return; - } - - m_device_nodes.append(sysfs_usb_device_or_error.release_value()); -} - -void SysFSUSBBusDirectory::unplug(USB::Device& deleted_device) +void SysFSUSBBusDirectory::unplug(Badge<USB::Hub>, SysFSUSBDeviceInformation& removed_device_info_node) { - SpinlockLocker lock(m_lock); - auto device_node = device_node_for(deleted_device); - VERIFY(device_node); - device_node->m_list_node.remove(); + MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> { + list.remove(removed_device_info_node); + return {}; + })); } SysFSUSBBusDirectory& SysFSUSBBusDirectory::the() { - VERIFY(s_procfs_usb_bus_directory); - return *s_procfs_usb_bus_directory; + VERIFY(s_sysfs_usb_bus_directory); + return *s_sysfs_usb_bus_directory; } UNMAP_AFTER_INIT SysFSUSBBusDirectory::SysFSUSBBusDirectory(SysFSBusDirectory& buses_directory) @@ -59,7 +42,7 @@ UNMAP_AFTER_INIT void SysFSUSBBusDirectory::initialize() { auto directory = adopt_ref(*new SysFSUSBBusDirectory(SysFSComponentRegistry::the().buses_directory())); SysFSComponentRegistry::the().register_new_bus_directory(directory); - s_procfs_usb_bus_directory = directory; + s_sysfs_usb_bus_directory = directory; } ErrorOr<NonnullRefPtr<SysFSUSBDeviceInformation>> SysFSUSBDeviceInformation::create(USB::Device& device) diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h index 197e597bcf..158a92a90a 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h @@ -6,7 +6,9 @@ #pragma once +#include <AK/Badge.h> #include <Kernel/Bus/USB/USBDevice.h> +#include <Kernel/Bus/USB/USBHub.h> #include <Kernel/FileSystem/SysFS/Component.h> #include <Kernel/FileSystem/SysFS/Subsystems/Bus/USB/DeviceInformation.h> #include <Kernel/Locking/Spinlock.h> @@ -20,15 +22,11 @@ public: virtual StringView name() const override { return "usb"sv; } - void plug(USB::Device&); - void unplug(USB::Device&); + void plug(Badge<USB::Hub>, SysFSUSBDeviceInformation&); + void unplug(Badge<USB::Hub>, SysFSUSBDeviceInformation&); private: explicit SysFSUSBBusDirectory(SysFSBusDirectory&); - - RefPtr<SysFSUSBDeviceInformation> device_node_for(USB::Device& device); - - IntrusiveList<&SysFSUSBDeviceInformation::m_list_node> m_device_nodes; mutable Spinlock m_lock; }; diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/DeviceInformation.h b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/DeviceInformation.h index 07f074a45d..afdcf32399 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/DeviceInformation.h +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/DeviceInformation.h @@ -23,15 +23,11 @@ public: static ErrorOr<NonnullRefPtr<SysFSUSBDeviceInformation>> create(USB::Device&); virtual StringView name() const override { return m_device_name->view(); } - RefPtr<USB::Device> device() const { return m_device; } - protected: SysFSUSBDeviceInformation(NonnullOwnPtr<KString> device_name, USB::Device& device); virtual ErrorOr<size_t> read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; - IntrusiveListNode<SysFSUSBDeviceInformation, RefPtr<SysFSUSBDeviceInformation>> m_list_node; - NonnullRefPtr<USB::Device> m_device; private: |