mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
Kernel/USB: Detach devices from their driver when they are detached
This commit is contained in:
parent
b4cd354bae
commit
d168bfabc4
Notes:
sideshowbarker
2024-07-17 01:00:06 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/d168bfabc4 Pull-request: https://github.com/SerenityOS/serenity/pull/21090 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/BertalanD Reviewed-by: https://github.com/kleinesfilmroellchen ✅ Reviewed-by: https://github.com/supercomputer7 ✅
3 changed files with 15 additions and 0 deletions
|
@ -39,6 +39,7 @@ ErrorOr<NonnullLockRefPtr<Device>> Device::try_create(USBController const& contr
|
|||
if (result.is_error())
|
||||
continue;
|
||||
dbgln_if(USB_DEBUG, "Found driver {} for device {:04x}:{:04x}!", driver->name(), device->m_vendor_id, device->m_product_id);
|
||||
device->set_driver(driver);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <AK/OwnPtr.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <Kernel/Bus/USB/Drivers/USBDriver.h>
|
||||
#include <Kernel/Bus/USB/USBConfiguration.h>
|
||||
#include <Kernel/Bus/USB/USBPipe.h>
|
||||
#include <Kernel/Locking/SpinlockProtected.h>
|
||||
|
@ -58,6 +59,14 @@ public:
|
|||
|
||||
Vector<USBConfiguration> const& configurations() const { return m_configurations; }
|
||||
|
||||
void set_driver(Driver& driver) { m_driver = driver; }
|
||||
void detach()
|
||||
{
|
||||
if (m_driver)
|
||||
m_driver->detach(*this);
|
||||
m_driver = nullptr;
|
||||
}
|
||||
|
||||
SpinlockProtected<RefPtr<SysFSUSBDeviceInformation>, LockRank::None>& sysfs_device_info_node(Badge<USB::Hub>) { return m_sysfs_device_info_node; }
|
||||
|
||||
protected:
|
||||
|
@ -76,6 +85,8 @@ protected:
|
|||
NonnullLockRefPtr<USBController> m_controller;
|
||||
NonnullOwnPtr<ControlPipe> m_default_pipe; // Default communication pipe (endpoint0) used during enumeration
|
||||
|
||||
LockRefPtr<Driver> m_driver;
|
||||
|
||||
private:
|
||||
IntrusiveListNode<Device, NonnullLockRefPtr<Device>> m_hub_child_node;
|
||||
|
||||
|
|
|
@ -295,6 +295,9 @@ void Hub::check_for_port_updates()
|
|||
auto* hub_child = static_cast<Hub*>(device_to_remove.ptr());
|
||||
hub_child->remove_children_from_sysfs();
|
||||
}
|
||||
|
||||
device_to_remove->detach();
|
||||
|
||||
m_children.remove(*device_to_remove);
|
||||
} else {
|
||||
dbgln_if(USB_DEBUG, "USB Hub: No child set up on port {}, ignoring detachment.", port_number);
|
||||
|
|
Loading…
Add table
Reference in a new issue