Skip to content

Commit 262687e

Browse files
committed
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. svn path=/branches/GSoC_2016/USB/; revision=72367
1 parent ce01b38 commit 262687e

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

drivers/usb/usbhub/fdo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,8 @@ CreateUsbChildDeviceObject(
13401340
goto Cleanup;
13411341
}
13421342

1343+
UsbChildExtension->IsRemovePending = FALSE;
1344+
13431345
HubDeviceExtension->ChildDeviceObject[ChildDeviceCount] = NewChildDeviceObject;
13441346
HubDeviceExtension->InstanceCount++;
13451347

drivers/usb/usbhub/pdo.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,20 @@ USBHUB_PdoHandleInternalDeviceControl(
190190

191191
ChildDeviceExtension = (PHUB_CHILDDEVICE_EXTENSION)DeviceObject->DeviceExtension;
192192
ASSERT(ChildDeviceExtension->Common.IsFDO == FALSE);
193-
HubDeviceExtension = (PHUB_DEVICE_EXTENSION)ChildDeviceExtension->ParentDeviceObject->DeviceExtension;
194-
RootHubDeviceObject = HubDeviceExtension->RootHubPhysicalDeviceObject;
195193

196-
if(!IsValidPDO(DeviceObject))
194+
if (ChildDeviceExtension->IsRemovePending || !IsValidPDO(DeviceObject))
197195
{
196+
// Parent or child device was surprise removed.
198197
DPRINT1("[USBHUB] Request for removed device object %p\n", DeviceObject);
199198
Irp->IoStatus.Status = STATUS_DEVICE_NOT_CONNECTED;
200199
Irp->IoStatus.Information = 0;
201200
IoCompleteRequest(Irp, IO_NO_INCREMENT);
202201
return STATUS_DEVICE_NOT_CONNECTED;
203202
}
204203

204+
HubDeviceExtension = (PHUB_DEVICE_EXTENSION)ChildDeviceExtension->ParentDeviceObject->DeviceExtension;
205+
RootHubDeviceObject = HubDeviceExtension->RootHubPhysicalDeviceObject;
206+
205207
switch (Stack->Parameters.DeviceIoControl.IoControlCode)
206208
{
207209
case IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO:
@@ -724,6 +726,11 @@ USBHUB_PdoHandlePnp(
724726
case IRP_MN_QUERY_STOP_DEVICE:
725727
case IRP_MN_QUERY_REMOVE_DEVICE:
726728
{
729+
// HERE SHOULD BE CHECKED INTERFACE COUNT PROVIED TO UPPER LAYER TO BE ZERO, AS WE ARE HANDLING
730+
// IRP_MN_QUERY_INTERFACE IN WRONG WAY, THAT WILL BE DONE LATER. SEE MSDN "IRP_MN_QUERY_INTERFACE"
731+
732+
UsbChildExtension->IsRemovePending = TRUE;
733+
727734
/* Sure, no problem */
728735
Status = STATUS_SUCCESS;
729736
Information = 0;
@@ -747,6 +754,14 @@ USBHUB_PdoHandlePnp(
747754
case IRP_MN_SURPRISE_REMOVAL:
748755
{
749756
DPRINT("[USBHUB] HandlePnp IRP_MN_SURPRISE_REMOVAL\n");
757+
758+
//
759+
// Here we should free all resources and stop all access, lets just set
760+
// the flag and do further clean-up in subsequent IRP_MN_REMOVE_DEVICE
761+
// We can receive this IRP when device is physically connected (on stop/start fail).
762+
//
763+
UsbChildExtension->IsRemovePending = TRUE;
764+
750765
Status = STATUS_SUCCESS;
751766
break;
752767
}

drivers/usb/usbhub/usbhub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef struct _HUB_CHILDDEVICE_EXTENSION
6161
UNICODE_STRING SymbolicLinkName;
6262
USB_BUS_INTERFACE_USBDI_V2 DeviceInterface;
6363
USB_DEVICE_INFORMATION_0 DeviceInformation;
64+
BOOLEAN IsRemovePending;
6465
} HUB_CHILDDEVICE_EXTENSION, *PHUB_CHILDDEVICE_EXTENSION;
6566

6667
typedef struct _HUB_DEVICE_EXTENSION

0 commit comments

Comments
 (0)