@@ -2034,10 +2034,12 @@ USBHUB_FdoHandlePnp(
2034
2034
NTSTATUS Status = STATUS_SUCCESS ;
2035
2035
PDEVICE_OBJECT ChildDeviceObject ;
2036
2036
PHUB_DEVICE_EXTENSION HubDeviceExtension ;
2037
+ PUSB_BUS_INTERFACE_HUB_V5 HubInterface ;
2037
2038
PHUB_CHILDDEVICE_EXTENSION ChildDeviceExtension ;
2038
2039
2039
2040
HubDeviceExtension = (PHUB_DEVICE_EXTENSION ) DeviceObject -> DeviceExtension ;
2040
2041
2042
+ HubInterface = & HubDeviceExtension -> HubInterface ;
2041
2043
Stack = IoGetCurrentIrpStackLocation (Irp );
2042
2044
2043
2045
Status = IoAcquireRemoveLock (& HubDeviceExtension -> Common .RemoveLock , Irp );
@@ -2175,15 +2177,69 @@ USBHUB_FdoHandlePnp(
2175
2177
}
2176
2178
case IRP_MN_REMOVE_DEVICE :
2177
2179
{
2178
- // Should be reworked later in this commits set
2179
2180
DPRINT ("IRP_MN_REMOVE_DEVICE\n" );
2181
+
2182
+ SET_NEW_PNP_STATE (HubDeviceExtension -> Common , Deleted );
2183
+
2184
+ IoReleaseRemoveLockAndWait (& HubDeviceExtension -> Common .RemoveLock , Irp );
2185
+
2186
+ //
2187
+ // Here we should remove all child PDOs. At this point all children
2188
+ // received and returned from IRP_MN_REMOVE so remove synchronization
2189
+ // isn't needed here
2190
+ //
2191
+
2192
+ KeAcquireGuardedMutex (& HubDeviceExtension -> HubMutexLock );
2193
+
2194
+ for (int i = 0 ; i < USB_MAXCHILDREN ; i ++ )
2195
+ {
2196
+ ChildDeviceObject = HubDeviceExtension -> ChildDeviceObject [i ];
2197
+ if (ChildDeviceObject )
2198
+ {
2199
+ PHUB_CHILDDEVICE_EXTENSION UsbChildExtension = (PHUB_CHILDDEVICE_EXTENSION )ChildDeviceObject -> DeviceExtension ;
2200
+
2201
+ SET_NEW_PNP_STATE (UsbChildExtension -> Common , Deleted );
2202
+
2203
+ // Remove the usb device
2204
+ if (UsbChildExtension -> UsbDeviceHandle )
2205
+ {
2206
+ Status = HubInterface -> RemoveUsbDevice (HubInterface -> BusContext , UsbChildExtension -> UsbDeviceHandle , 0 );
2207
+ ASSERT (Status == STATUS_SUCCESS );
2208
+ }
2209
+
2210
+ // Free full configuration descriptor
2211
+ if (UsbChildExtension -> FullConfigDesc )
2212
+ ExFreePool (UsbChildExtension -> FullConfigDesc );
2213
+
2214
+ // Free ID buffers
2215
+ if (UsbChildExtension -> usCompatibleIds .Buffer )
2216
+ ExFreePool (UsbChildExtension -> usCompatibleIds .Buffer );
2217
+
2218
+ if (UsbChildExtension -> usDeviceId .Buffer )
2219
+ ExFreePool (UsbChildExtension -> usDeviceId .Buffer );
2220
+
2221
+ if (UsbChildExtension -> usHardwareIds .Buffer )
2222
+ ExFreePool (UsbChildExtension -> usHardwareIds .Buffer );
2223
+
2224
+ if (UsbChildExtension -> usInstanceId .Buffer )
2225
+ ExFreePool (UsbChildExtension -> usInstanceId .Buffer );
2226
+
2227
+ DPRINT ("Deleting child PDO\n" );
2228
+ IoDeleteDevice (DeviceObject );
2229
+ ChildDeviceObject = NULL ;
2230
+ }
2231
+ }
2232
+
2233
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
2234
+
2180
2235
Irp -> IoStatus .Status = STATUS_SUCCESS ;
2181
- IoCompleteRequest ( Irp , IO_NO_INCREMENT );
2236
+ Status = ForwardIrpAndForget ( DeviceObject , Irp );
2182
2237
2183
2238
IoDetachDevice (HubDeviceExtension -> LowerDeviceObject );
2239
+ DPRINT ("Deleting FDO 0x%p\n" , DeviceObject );
2184
2240
IoDeleteDevice (DeviceObject );
2185
2241
2186
- return STATUS_SUCCESS ;
2242
+ return Status ;
2187
2243
}
2188
2244
case IRP_MN_QUERY_BUS_INFORMATION :
2189
2245
{
0 commit comments