Author: vmikayelyan
Date: Fri Aug 19 15:31:15 2016
New Revision: 72367

URL: http://svn.reactos.org/svn/reactos?rev=72367&view=rev
Log:
usb: hub: PDO: Add IsRemovePending flag to HUB_CHILDDEVICE_EXTENSION

This flag is set in IRP_MN_QUERY_REMOVE_DEVICE and IRP_MN_SURPRISE_REMOVAL,
and then checked in PDO's IRP dispatch routines to prevent starting of
any operation which can prevent device removal.

Modified:
    branches/GSoC_2016/USB/drivers/usb/usbhub/fdo.c
    branches/GSoC_2016/USB/drivers/usb/usbhub/pdo.c
    branches/GSoC_2016/USB/drivers/usb/usbhub/usbhub.h

Modified: branches/GSoC_2016/USB/drivers/usb/usbhub/fdo.c
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/USB/drivers/usb/usbhub/fdo.c?rev=72367&r1=72366&r2=72367&view=diff
==============================================================================
--- branches/GSoC_2016/USB/drivers/usb/usbhub/fdo.c     [iso-8859-1] (original)
+++ branches/GSoC_2016/USB/drivers/usb/usbhub/fdo.c     [iso-8859-1] Fri Aug 19 
15:31:15 2016
@@ -1339,6 +1339,8 @@
         DPRINT1("Failed to create strings needed to describe device to 
PNP.\n");
         goto Cleanup;
     }
+
+    UsbChildExtension->IsRemovePending = FALSE;
 
     HubDeviceExtension->ChildDeviceObject[ChildDeviceCount] = 
NewChildDeviceObject;
     HubDeviceExtension->InstanceCount++;

Modified: branches/GSoC_2016/USB/drivers/usb/usbhub/pdo.c
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/USB/drivers/usb/usbhub/pdo.c?rev=72367&r1=72366&r2=72367&view=diff
==============================================================================
--- branches/GSoC_2016/USB/drivers/usb/usbhub/pdo.c     [iso-8859-1] (original)
+++ branches/GSoC_2016/USB/drivers/usb/usbhub/pdo.c     [iso-8859-1] Fri Aug 19 
15:31:15 2016
@@ -190,17 +190,19 @@
 
     ChildDeviceExtension = 
(PHUB_CHILDDEVICE_EXTENSION)DeviceObject->DeviceExtension;
     ASSERT(ChildDeviceExtension->Common.IsFDO == FALSE);
-    HubDeviceExtension = 
(PHUB_DEVICE_EXTENSION)ChildDeviceExtension->ParentDeviceObject->DeviceExtension;
-    RootHubDeviceObject = HubDeviceExtension->RootHubPhysicalDeviceObject;
-
-    if(!IsValidPDO(DeviceObject))
-    {
+
+    if (ChildDeviceExtension->IsRemovePending || !IsValidPDO(DeviceObject))
+    {
+        // Parent or child device was surprise removed.
         DPRINT1("[USBHUB] Request for removed device object %p\n", 
DeviceObject);
         Irp->IoStatus.Status = STATUS_DEVICE_NOT_CONNECTED;
         Irp->IoStatus.Information = 0;
         IoCompleteRequest(Irp, IO_NO_INCREMENT);
         return STATUS_DEVICE_NOT_CONNECTED;
     }
+
+    HubDeviceExtension = 
(PHUB_DEVICE_EXTENSION)ChildDeviceExtension->ParentDeviceObject->DeviceExtension;
+    RootHubDeviceObject = HubDeviceExtension->RootHubPhysicalDeviceObject;
 
     switch (Stack->Parameters.DeviceIoControl.IoControlCode)
     {
@@ -724,6 +726,11 @@
         case IRP_MN_QUERY_STOP_DEVICE:
         case IRP_MN_QUERY_REMOVE_DEVICE:
         {
+            // HERE SHOULD BE CHECKED INTERFACE COUNT PROVIED TO UPPER LAYER 
TO BE ZERO, AS WE ARE HANDLING
+            // IRP_MN_QUERY_INTERFACE IN WRONG WAY, THAT WILL BE DONE LATER. 
SEE MSDN "IRP_MN_QUERY_INTERFACE"
+
+            UsbChildExtension->IsRemovePending = TRUE;
+
             /* Sure, no problem */
             Status = STATUS_SUCCESS;
             Information = 0;
@@ -747,6 +754,14 @@
         case IRP_MN_SURPRISE_REMOVAL:
         {
             DPRINT("[USBHUB] HandlePnp IRP_MN_SURPRISE_REMOVAL\n");
+
+            //
+            // Here we should free all resources and stop all access, lets 
just set
+            // the flag and do further clean-up in subsequent 
IRP_MN_REMOVE_DEVICE
+            // We can receive this IRP when device is physically connected (on 
stop/start fail).
+            //
+            UsbChildExtension->IsRemovePending = TRUE;
+
             Status = STATUS_SUCCESS;
             break;
         }

Modified: branches/GSoC_2016/USB/drivers/usb/usbhub/usbhub.h
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/USB/drivers/usb/usbhub/usbhub.h?rev=72367&r1=72366&r2=72367&view=diff
==============================================================================
--- branches/GSoC_2016/USB/drivers/usb/usbhub/usbhub.h  [iso-8859-1] (original)
+++ branches/GSoC_2016/USB/drivers/usb/usbhub/usbhub.h  [iso-8859-1] Fri Aug 19 
15:31:15 2016
@@ -61,6 +61,7 @@
     UNICODE_STRING SymbolicLinkName;
     USB_BUS_INTERFACE_USBDI_V2 DeviceInterface;
     USB_DEVICE_INFORMATION_0 DeviceInformation;
+    BOOLEAN IsRemovePending;
 } HUB_CHILDDEVICE_EXTENSION, *PHUB_CHILDDEVICE_EXTENSION;
 
 typedef struct _HUB_DEVICE_EXTENSION


Reply via email to