mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:52:43 +00:00 
			
		
		
		
	Kernel/USB: Detach devices from their driver when they are detached
This commit is contained in:
		
							parent
							
								
									b4cd354bae
								
							
						
					
					
						commit
						d168bfabc4
					
				
					 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
		Add a link
		
	
		Reference in a new issue
	
	 Hendiadyoin1
						Hendiadyoin1