@@ -570,10 +570,7 @@ USBHUB_PdoHandlePnp(
570
570
PIO_STACK_LOCATION Stack ;
571
571
ULONG_PTR Information = 0 ;
572
572
PHUB_CHILDDEVICE_EXTENSION UsbChildExtension ;
573
- ULONG Index ;
574
- ULONG bFound ;
575
573
PDEVICE_RELATIONS DeviceRelation ;
576
- PDEVICE_OBJECT ParentDevice ;
577
574
578
575
UsbChildExtension = (PHUB_CHILDDEVICE_EXTENSION )DeviceObject -> DeviceExtension ;
579
576
Stack = IoGetCurrentIrpStackLocation (Irp );
@@ -664,42 +661,47 @@ USBHUB_PdoHandlePnp(
664
661
{
665
662
PHUB_DEVICE_EXTENSION HubDeviceExtension = (PHUB_DEVICE_EXTENSION )UsbChildExtension -> ParentDeviceObject -> DeviceExtension ;
666
663
PUSB_BUS_INTERFACE_HUB_V5 HubInterface = & HubDeviceExtension -> HubInterface ;
667
- ParentDevice = UsbChildExtension -> ParentDeviceObject ;
668
664
669
665
DPRINT ("IRP_MJ_PNP / IRP_MN_REMOVE_DEVICE\n" );
670
666
671
- /* remove us from pdo list */
672
- bFound = FALSE;
673
- for (Index = 0 ; Index < USB_MAXCHILDREN ; Index ++ )
667
+ if (!IsValidPDO (DeviceObject ))
674
668
{
675
- if (HubDeviceExtension -> ChildDeviceObject [Index ] == DeviceObject )
669
+ // Parent or child device was surprise removed, freeing resources allocated for child device.
670
+
671
+ // Remove the usb device
672
+ if (UsbChildExtension -> UsbDeviceHandle )
676
673
{
677
- /* Remove the device */
678
- Status = HubInterface -> RemoveUsbDevice (HubDeviceExtension -> UsbDInterface .BusContext , UsbChildExtension -> UsbDeviceHandle , 0 );
674
+ Status = HubInterface -> RemoveUsbDevice (HubInterface -> BusContext , UsbChildExtension -> UsbDeviceHandle , 0 );
675
+ ASSERT (Status == STATUS_SUCCESS );
676
+ }
677
+ // Free full configuration descriptor
678
+ if (UsbChildExtension -> FullConfigDesc )
679
+ ExFreePool (UsbChildExtension -> FullConfigDesc );
679
680
680
- /* FIXME handle error */
681
- ASSERT (Status == STATUS_SUCCESS );
681
+ // Free ID buffers
682
+ if (UsbChildExtension -> usCompatibleIds .Buffer )
683
+ ExFreePool (UsbChildExtension -> usCompatibleIds .Buffer );
682
684
683
- /* remove us */
684
- HubDeviceExtension -> ChildDeviceObject [Index ] = NULL ;
685
- bFound = TRUE;
686
- break ;
687
- }
685
+ if (UsbChildExtension -> usDeviceId .Buffer )
686
+ ExFreePool (UsbChildExtension -> usDeviceId .Buffer );
687
+
688
+ if (UsbChildExtension -> usHardwareIds .Buffer )
689
+ ExFreePool (UsbChildExtension -> usHardwareIds .Buffer );
690
+
691
+ if (UsbChildExtension -> usInstanceId .Buffer )
692
+ ExFreePool (UsbChildExtension -> usInstanceId .Buffer );
693
+
694
+ // Delete child PDO
695
+ IoDeleteDevice (DeviceObject );
688
696
}
689
697
698
+ // Device is physically presented, so we leave its PDO undeleted.
699
+ ASSERT (UsbChildExtension -> IsRemovePending == TRUE);
700
+
690
701
/* Complete the IRP */
691
702
Irp -> IoStatus .Status = STATUS_SUCCESS ;
692
703
IoCompleteRequest (Irp , IO_NO_INCREMENT );
693
704
694
- /* delete device */
695
- IoDeleteDevice (DeviceObject );
696
-
697
- if (bFound )
698
- {
699
- /* invalidate device relations */
700
- IoInvalidateDeviceRelations (ParentDevice , BusRelations );
701
- }
702
-
703
705
return STATUS_SUCCESS ;
704
706
}
705
707
case IRP_MN_QUERY_DEVICE_RELATIONS :
0 commit comments