[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
This commit is contained in:
Johannes Anderwald 2012-02-05 15:36:00 +00:00
parent 82848d85df
commit cf494ea401
9 changed files with 144 additions and 96 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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

View file

@ -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:

View file

@ -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;
//

View file

@ -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:

View file

@ -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
//
continue;
}
//
// done
// 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

View file

@ -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

View file

@ -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;
//