From: Johannes Anderwald Date: Sun, 5 Feb 2012 15:36:00 +0000 (+0000) Subject: [HIDCLASS] X-Git-Tag: backups/usb-bringup-trunk@60667~43 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=cf494ea401ed00c1856bf07d1cf54d2bc78131e7 [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 svn path=/branches/usb-bringup-trunk/; revision=55429 --- diff --git a/drivers/hid/hidclass/hidclass.c b/drivers/hid/hidclass/hidclass.c index 3b6a662bedf..39c31c473f9 100644 --- a/drivers/hid/hidclass/hidclass.c +++ b/drivers/hid/hidclass/hidclass.c @@ -79,11 +79,18 @@ HidClassAddDevice( 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); diff --git a/drivers/hid/hidclass/pdo.c b/drivers/hid/hidclass/pdo.c index c5045b8489a..b97ae573577 100644 --- a/drivers/hid/hidclass/pdo.c +++ b/drivers/hid/hidclass/pdo.c @@ -354,7 +354,7 @@ HidClassPDO_PnP( NTSTATUS Status; PPNP_BUS_INFORMATION BusInformation; PDEVICE_RELATIONS DeviceRelation; - ULONG Index; + ULONG Index, bFound; // // get device extension @@ -535,6 +535,7 @@ HidClassPDO_PnP( // // 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 @@ HidClassPDO_PnP( // // remove us // + bFound = TRUE; PDODeviceExtension->FDODeviceExtension->DeviceRelations->Objects[Index] = NULL; break; } @@ -551,8 +553,11 @@ HidClassPDO_PnP( 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; } diff --git a/drivers/hid/hidusb/hidusb.c b/drivers/hid/hidusb/hidusb.c index 40ac22d29b0..6913892d31f 100644 --- a/drivers/hid/hidusb/hidusb.c +++ b/drivers/hid/hidusb/hidusb.c @@ -1662,19 +1662,10 @@ HidPnp( 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 diff --git a/drivers/usb/usbccgp/pdo.c b/drivers/usb/usbccgp/pdo.c index a78f7cea3c2..3d7cb01cf6a 100644 --- a/drivers/usb/usbccgp/pdo.c +++ b/drivers/usb/usbccgp/pdo.c @@ -307,7 +307,7 @@ PDO_HandlePnp( PIO_STACK_LOCATION IoStack; PPDO_DEVICE_EXTENSION PDODeviceExtension; NTSTATUS Status; - ULONG Index; + ULONG Index, bFound; // // get current stack location @@ -355,6 +355,7 @@ PDO_HandlePnp( // // 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 @@ PDO_HandlePnp( // remove us // PDODeviceExtension->FDODeviceExtension->ChildPDO[Index] = NULL; + bFound = TRUE; break; } } @@ -373,10 +375,13 @@ PDO_HandlePnp( 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: diff --git a/drivers/usb/usbehci_new/usb_request.cpp b/drivers/usb/usbehci_new/usb_request.cpp index aff29cbd55e..8a0d630d146 100644 --- a/drivers/usb/usbehci_new/usb_request.cpp +++ b/drivers/usb/usbehci_new/usb_request.cpp @@ -743,7 +743,7 @@ CUSBRequest::BuildControlTransferQueueHead( // // 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; // diff --git a/drivers/usb/usbhub_new/pdo.c b/drivers/usb/usbhub_new/pdo.c index 89e87f77cba..fadaa57a341 100644 --- a/drivers/usb/usbhub_new/pdo.c +++ b/drivers/usb/usbhub_new/pdo.c @@ -486,6 +486,7 @@ USBHUB_PdoHandlePnp( 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 @@ USBHUB_PdoHandlePnp( 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 @@ USBHUB_PdoHandlePnp( 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: diff --git a/drivers/usb/usbohci/usb_queue.cpp b/drivers/usb/usbohci/usb_queue.cpp index dabc4586a6b..67d425b6eda 100644 --- a/drivers/usb/usbohci/usb_queue.cpp +++ b/drivers/usb/usbohci/usb_queue.cpp @@ -622,75 +622,84 @@ CUSBQueue::TransferDescriptorCompletionCallback( 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)) + do { // - // cleanup endpoint + // find transfer descriptor in control list // - CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); + Status = FindTransferDescriptorInEndpoint(m_ControlHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); + if (NT_SUCCESS(Status)) + { + // + // cleanup endpoint + // + CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); - // - // done - // - return; - } + // + // done + // + continue; + } - // - // find transfer descriptor in bulk list - // - Status = FindTransferDescriptorInEndpoint(m_BulkHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); - if (NT_SUCCESS(Status)) - { // - // cleanup endpoint + // find transfer descriptor in bulk list // - CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); + Status = FindTransferDescriptorInEndpoint(m_BulkHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); + if (NT_SUCCESS(Status)) + { + // + // cleanup endpoint + // + CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); - // - // done - // - return; - } + // + // done + // + continue; + } - // - // find transfer descriptor in interrupt list - // - Status = FindTransferDescriptorInInterruptHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); - if (NT_SUCCESS(Status)) - { // - // cleanup endpoint + // find transfer descriptor in interrupt list // - CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); + Status = FindTransferDescriptorInInterruptHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); + if (NT_SUCCESS(Status)) + { + // + // cleanup endpoint + // + CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); - // - // done - // - return; - } + // + // done + // + continue; + } - // - // last try: find the descriptor in isochronous list - // - Status = FindTransferDescriptorInIsochronousHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); - if (NT_SUCCESS(Status)) - { // - // cleanup endpoint + // last try: find the descriptor in isochronous list // - DPRINT1("ISO endpoint complete\n"); -ASSERT(FALSE); - CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); + Status = FindTransferDescriptorInIsochronousHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor); + if (NT_SUCCESS(Status)) + { + // + // cleanup endpoint + // + DPRINT1("ISO endpoint complete\n"); + ASSERT(FALSE); + CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor); + + // + // done + // + continue; + } // - // done + // no more completed descriptors found // return; - } + + }while(TRUE); // // hardware reported dead endpoint completed diff --git a/drivers/usb/usbstor/pdo.c b/drivers/usb/usbstor/pdo.c index 3361351bee8..eda74ddf9c1 100644 --- a/drivers/usb/usbstor/pdo.c +++ b/drivers/usb/usbstor/pdo.c @@ -773,6 +773,7 @@ USBSTOR_PdoHandlePnp( PPDO_DEVICE_EXTENSION DeviceExtension; NTSTATUS Status; PDEVICE_CAPABILITIES Caps; + ULONG bDelete; // // get current stack location @@ -845,13 +846,31 @@ USBSTOR_PdoHandlePnp( { 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 @@ USBSTOR_PdoHandlePnp( // 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 @@ USBSTOR_CreatePDO( RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION)); PDODeviceExtension->Common.IsFDO = FALSE; PDODeviceExtension->LowerDeviceObject = DeviceObject; + PDODeviceExtension->PDODeviceObject = ChildDeviceObject; // // set device flags diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index 7c0e0d4e84e..b2b9e33be4b 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -79,6 +79,7 @@ typedef struct 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; //