Author: janderwald Date: Sun Feb 5 15:36:00 2012 New Revision: 55429
URL: http://svn.reactos.org/svn/reactos?rev=55429&view=rev Log: [HIDCLASS] - Check if attaching to device stack failed. In that case fail the request [HIDUSB] - Always set SupriseRemovalOk [USBCCGP] [HIDCLASS] [USBHUB] [USBSTOR] - Check if the pdo is still in the pdo list. Only call IoDeleteDevice in that case
Modified: branches/usb-bringup-trunk/drivers/hid/hidclass/hidclass.c branches/usb-bringup-trunk/drivers/hid/hidclass/pdo.c branches/usb-bringup-trunk/drivers/hid/hidusb/hidusb.c branches/usb-bringup-trunk/drivers/usb/usbccgp/pdo.c branches/usb-bringup-trunk/drivers/usb/usbehci_new/usb_request.cpp branches/usb-bringup-trunk/drivers/usb/usbhub_new/pdo.c branches/usb-bringup-trunk/drivers/usb/usbohci/usb_queue.cpp branches/usb-bringup-trunk/drivers/usb/usbstor/pdo.c branches/usb-bringup-trunk/drivers/usb/usbstor/usbstor.h
Modified: branches/usb-bringup-trunk/drivers/hid/hidclass/hidclass.c URL: http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/hid/hi... ============================================================================== --- branches/usb-bringup-trunk/drivers/hid/hidclass/hidclass.c [iso-8859-1] (original) +++ branches/usb-bringup-trunk/drivers/hid/hidclass/hidclass.c [iso-8859-1] Sun Feb 5 15:36:00 2012 @@ -79,11 +79,18 @@ RtlZeroMemory(FDODeviceExtension, sizeof(HIDCLASS_FDO_EXTENSION));
/* initialize device extension */ + FDODeviceExtension->Common.IsFDO = TRUE; + FDODeviceExtension->Common.DriverExtension = DriverExtension; FDODeviceExtension->Common.HidDeviceExtension.PhysicalDeviceObject = PhysicalDeviceObject; FDODeviceExtension->Common.HidDeviceExtension.MiniDeviceExtension = (PVOID)((ULONG_PTR)FDODeviceExtension + sizeof(HIDCLASS_FDO_EXTENSION)); FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject = IoAttachDeviceToDeviceStack(NewDeviceObject, PhysicalDeviceObject); - FDODeviceExtension->Common.IsFDO = TRUE; - FDODeviceExtension->Common.DriverExtension = DriverExtension; + if (FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject == NULL) + { + /* no PDO */ + IoDeleteDevice(NewDeviceObject); + DPRINT1("[HIDCLASS] failed to attach to device stack\n"); + return STATUS_DEVICE_REMOVED; + }
/* sanity check */ ASSERT(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject);
Modified: branches/usb-bringup-trunk/drivers/hid/hidclass/pdo.c URL: http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/hid/hi... ============================================================================== --- branches/usb-bringup-trunk/drivers/hid/hidclass/pdo.c [iso-8859-1] (original) +++ branches/usb-bringup-trunk/drivers/hid/hidclass/pdo.c [iso-8859-1] Sun Feb 5 15:36:00 2012 @@ -354,7 +354,7 @@ NTSTATUS Status; PPNP_BUS_INFORMATION BusInformation; PDEVICE_RELATIONS DeviceRelation; - ULONG Index; + ULONG Index, bFound;
// // get device extension @@ -535,6 +535,7 @@ // // remove us from the fdo's pdo list // + bFound = FALSE; for(Index = 0; Index < PDODeviceExtension->FDODeviceExtension->DeviceRelations->Count; Index++) { if (PDODeviceExtension->FDODeviceExtension->DeviceRelations->Objects[Index] == DeviceObject) @@ -542,6 +543,7 @@ // // remove us // + bFound = TRUE; PDODeviceExtension->FDODeviceExtension->DeviceRelations->Objects[Index] = NULL; break; } @@ -551,8 +553,11 @@ Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT);
- /* Delete our device object*/ - IoDeleteDevice(DeviceObject); + if (bFound) + { + /* Delete our device object*/ + IoDeleteDevice(DeviceObject); + }
return STATUS_SUCCESS; }
Modified: branches/usb-bringup-trunk/drivers/hid/hidusb/hidusb.c URL: http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/hid/hi... ============================================================================== --- branches/usb-bringup-trunk/drivers/hid/hidusb/hidusb.c [iso-8859-1] (original) +++ branches/usb-bringup-trunk/drivers/hid/hidusb/hidusb.c [iso-8859-1] Sun Feb 5 15:36:00 2012 @@ -1662,19 +1662,10 @@ Status = Irp->IoStatus.Status; }
- if (NT_SUCCESS(Status)) - { - // - // driver supports D1 & D2 - // - IoStack->Parameters.DeviceCapabilities.Capabilities->DeviceD1 = TRUE; - IoStack->Parameters.DeviceCapabilities.Capabilities->DeviceD2 = TRUE; - - // - // don't need to safely remove - // - IoStack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = TRUE; - } + // + // don't need to safely remove + // + IoStack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = TRUE;
// // done
Modified: branches/usb-bringup-trunk/drivers/usb/usbccgp/pdo.c URL: http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/us... ============================================================================== --- branches/usb-bringup-trunk/drivers/usb/usbccgp/pdo.c [iso-8859-1] (original) +++ branches/usb-bringup-trunk/drivers/usb/usbccgp/pdo.c [iso-8859-1] Sun Feb 5 15:36:00 2012 @@ -307,7 +307,7 @@ PIO_STACK_LOCATION IoStack; PPDO_DEVICE_EXTENSION PDODeviceExtension; NTSTATUS Status; - ULONG Index; + ULONG Index, bFound;
// // get current stack location @@ -355,6 +355,7 @@ // // remove us from the fdo's pdo list // + bFound = FALSE; for(Index = 0; Index < PDODeviceExtension->FDODeviceExtension->FunctionDescriptorCount; Index++) { if (PDODeviceExtension->FDODeviceExtension->ChildPDO[Index] == DeviceObject) @@ -363,6 +364,7 @@ // remove us // PDODeviceExtension->FDODeviceExtension->ChildPDO[Index] = NULL; + bFound = TRUE; break; } } @@ -373,10 +375,13 @@ Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT);
- // - // Delete the device object - // - IoDeleteDevice(DeviceObject); + if (bFound) + { + // + // Delete the device object + // + IoDeleteDevice(DeviceObject); + } return STATUS_SUCCESS; } case IRP_MN_QUERY_CAPABILITIES:
Modified: branches/usb-bringup-trunk/drivers/usb/usbehci_new/usb_request.cpp URL: http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/us... ============================================================================== --- branches/usb-bringup-trunk/drivers/usb/usbehci_new/usb_request.cpp [iso-8859-1] (original) +++ branches/usb-bringup-trunk/drivers/usb/usbehci_new/usb_request.cpp [iso-8859-1] Sun Feb 5 15:36:00 2012 @@ -743,7 +743,7 @@ // // no buffer, setup in descriptor // - m_TransferDescriptors[1]->Token.Bits.PIDCode = PID_CODE_IN_TOKEN; + m_TransferDescriptors[1]->Token.Bits.PIDCode = PID_CODE_OUT_TOKEN; m_TransferDescriptors[1]->Token.Bits.TotalBytesToTransfer = 0;
//
Modified: branches/usb-bringup-trunk/drivers/usb/usbhub_new/pdo.c URL: http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/us... ============================================================================== --- branches/usb-bringup-trunk/drivers/usb/usbhub_new/pdo.c [iso-8859-1] (original) +++ branches/usb-bringup-trunk/drivers/usb/usbhub_new/pdo.c [iso-8859-1] Sun Feb 5 15:36:00 2012 @@ -486,6 +486,7 @@ ULONG_PTR Information = 0; PHUB_CHILDDEVICE_EXTENSION UsbChildExtension; ULONG Index; + ULONG bFound; PDEVICE_RELATIONS DeviceRelation;
UsbChildExtension = (PHUB_CHILDDEVICE_EXTENSION)DeviceObject->DeviceExtension; @@ -577,19 +578,21 @@
DPRINT1("IRP_MJ_PNP / IRP_MN_REMOVE_DEVICE\n");
- /* Remove the device */ - Status = HubInterface->RemoveUsbDevice(HubDeviceExtension->UsbDInterface.BusContext, UsbChildExtension->UsbDeviceHandle, 0); - - /* FIXME handle error */ - ASSERT(Status == STATUS_SUCCESS); - /* remove us from pdo list */ + bFound = FALSE; for(Index = 0; Index < USB_MAXCHILDREN; Index++) { if (HubDeviceExtension->ChildDeviceObject[Index] == DeviceObject) { + /* Remove the device */ + Status = HubInterface->RemoveUsbDevice(HubDeviceExtension->UsbDInterface.BusContext, UsbChildExtension->UsbDeviceHandle, 0); + + /* FIXME handle error */ + ASSERT(Status == STATUS_SUCCESS); + /* remove us */ HubDeviceExtension->ChildDeviceObject[Index] = NULL; + bFound = TRUE; break; } } @@ -598,8 +601,12 @@ Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT);
- /* Delete the device object */ - IoDeleteDevice(DeviceObject); + if (bFound) + { + /* Delete the device object */ + IoDeleteDevice(DeviceObject); + } + return STATUS_SUCCESS; } case IRP_MN_QUERY_DEVICE_RELATIONS:
Modified: branches/usb-bringup-trunk/drivers/usb/usbohci/usb_queue.cpp URL: http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/us... ============================================================================== --- branches/usb-bringup-trunk/drivers/usb/usbohci/usb_queue.cpp [iso-8859-1] (original) +++ branches/usb-bringup-trunk/drivers/usb/usbohci/usb_queue.cpp [iso-8859-1] Sun Feb 5 15:36:00 2012 @@ -622,75 +622,84 @@
DPRINT("CUSBQueue::TransferDescriptorCompletionCallback transfer descriptor %x\n", TransferDescriptorLogicalAddress);
- // - // find transfer descriptor in control list - // - Status = FindTransferDescriptorInEndpoint(m_ControlHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); - if (NT_SUCCESS(Status)) - { - // - // cleanup endpoint - // - CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); - - // - // done + do + { + // + // find transfer descriptor in control list + // + Status = FindTransferDescriptorInEndpoint(m_ControlHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); + if (NT_SUCCESS(Status)) + { + // + // cleanup endpoint + // + CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); + + // + // done + // + continue; + } + + // + // find transfer descriptor in bulk list + // + Status = FindTransferDescriptorInEndpoint(m_BulkHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); + if (NT_SUCCESS(Status)) + { + // + // cleanup endpoint + // + CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); + + // + // done + // + continue; + } + + // + // find transfer descriptor in interrupt list + // + Status = FindTransferDescriptorInInterruptHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); + if (NT_SUCCESS(Status)) + { + // + // cleanup endpoint + // + CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); + + // + // done + // + continue; + } + + // + // last try: find the descriptor in isochronous list + // + Status = FindTransferDescriptorInIsochronousHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); + if (NT_SUCCESS(Status)) + { + // + // cleanup endpoint + // + DPRINT1("ISO endpoint complete\n"); + ASSERT(FALSE); + CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); + + // + // done + // + continue; + } + + // + // no more completed descriptors found // return; - } - - // - // find transfer descriptor in bulk list - // - Status = FindTransferDescriptorInEndpoint(m_BulkHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); - if (NT_SUCCESS(Status)) - { - // - // cleanup endpoint - // - CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); - - // - // done - // - return; - } - - // - // find transfer descriptor in interrupt list - // - Status = FindTransferDescriptorInInterruptHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); - if (NT_SUCCESS(Status)) - { - // - // cleanup endpoint - // - CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); - - // - // done - // - return; - } - - // - // last try: find the descriptor in isochronous list - // - Status = FindTransferDescriptorInIsochronousHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); - if (NT_SUCCESS(Status)) - { - // - // cleanup endpoint - // - DPRINT1("ISO endpoint complete\n"); -ASSERT(FALSE); - CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); - - // - // done - // - return; - } + + }while(TRUE);
// // hardware reported dead endpoint completed
Modified: branches/usb-bringup-trunk/drivers/usb/usbstor/pdo.c URL: http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/us... ============================================================================== --- branches/usb-bringup-trunk/drivers/usb/usbstor/pdo.c [iso-8859-1] (original) +++ branches/usb-bringup-trunk/drivers/usb/usbstor/pdo.c [iso-8859-1] Sun Feb 5 15:36:00 2012 @@ -773,6 +773,7 @@ PPDO_DEVICE_EXTENSION DeviceExtension; NTSTATUS Status; PDEVICE_CAPABILITIES Caps; + ULONG bDelete;
// // get current stack location @@ -845,13 +846,31 @@ { DPRINT1("IRP_MN_REMOVE_DEVICE\n");
+ if(*DeviceExtension->PDODeviceObject != NULL) + { + // + // clear entry in FDO pdo list + // + *DeviceExtension->PDODeviceObject = NULL; + bDelete = TRUE; + } + else + { + // + // device object already marked for deletion + // + bDelete = FALSE; + } + /* Complete the IRP */ Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT);
- /* Delete the device object */ - IoDeleteDevice(DeviceObject); - + if (bDelete) + { + /* Delete the device object */ + IoDeleteDevice(DeviceObject); + } return STATUS_SUCCESS; } case IRP_MN_QUERY_CAPABILITIES: @@ -880,7 +899,10 @@ // if we're not claimed it's ok // if (DeviceExtension->Claimed) + { Status = STATUS_UNSUCCESSFUL; + DPRINT1("[USBSTOR] Request %x fails because device is still claimed\n", IoStack->MinorFunction); + } else Status = STATUS_SUCCESS; break; @@ -961,6 +983,7 @@ RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION)); PDODeviceExtension->Common.IsFDO = FALSE; PDODeviceExtension->LowerDeviceObject = DeviceObject; + PDODeviceExtension->PDODeviceObject = ChildDeviceObject;
// // set device flags
Modified: branches/usb-bringup-trunk/drivers/usb/usbstor/usbstor.h URL: http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/us... ============================================================================== --- branches/usb-bringup-trunk/drivers/usb/usbstor/usbstor.h [iso-8859-1] (original) +++ branches/usb-bringup-trunk/drivers/usb/usbstor/usbstor.h [iso-8859-1] Sun Feb 5 15:36:00 2012 @@ -79,6 +79,7 @@ UCHAR Claimed; // indicating if it has been claimed by upper driver ULONG BlockLength; // length of block ULONG LastLogicBlockAddress; // last block address + PDEVICE_OBJECT *PDODeviceObject; // entry in pdo list }PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
//