mirror of
https://github.com/reactos/reactos.git
synced 2025-06-05 09:20:30 +00:00
[USBSTOR]
- Fix broken IRP error handling and leaking memory svn path=/branches/usb-bringup-trunk/; revision=55155
This commit is contained in:
parent
75947d6708
commit
2f5db208de
3 changed files with 99 additions and 85 deletions
|
@ -60,13 +60,13 @@ USBSTOR_ResetPipeWithHandle(
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
USBSTOR_HandleTransferError(
|
USBSTOR_HandleTransferError(
|
||||||
PDEVICE_OBJECT DeviceObject,
|
PDEVICE_OBJECT DeviceObject,
|
||||||
PIRP Irp,
|
|
||||||
PIRP_CONTEXT Context)
|
PIRP_CONTEXT Context)
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PIO_STACK_LOCATION Stack;
|
PIO_STACK_LOCATION Stack;
|
||||||
USBD_PIPE_HANDLE PipeHandle;
|
USBD_PIPE_HANDLE PipeHandle;
|
||||||
PSCSI_REQUEST_BLOCK Request;
|
PSCSI_REQUEST_BLOCK Request;
|
||||||
|
PCDB pCDB;
|
||||||
|
|
||||||
DPRINT1("Entered Handle Transfer Error\n");
|
DPRINT1("Entered Handle Transfer Error\n");
|
||||||
//
|
//
|
||||||
|
@ -121,20 +121,41 @@ USBSTOR_HandleTransferError(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stack = IoGetCurrentIrpStackLocation(Context->Irp);
|
||||||
|
Request = (PSCSI_REQUEST_BLOCK)Stack->Parameters.Others.Argument1;
|
||||||
|
pCDB = (PCDB)Request->Cdb;
|
||||||
if (Status != STATUS_SUCCESS)
|
if (Status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
Irp->IoStatus.Status = Status;
|
/* Complete the master IRP */
|
||||||
Irp->IoStatus.Information = 0;
|
Context->Irp->IoStatus.Status = Status;
|
||||||
|
Context->Irp->IoStatus.Information = 0;
|
||||||
|
IoCompleteRequest(Context->Irp, IO_NO_INCREMENT);
|
||||||
|
|
||||||
|
/* Start the next request */
|
||||||
|
USBSTOR_QueueTerminateRequest(Context->PDODeviceExtension->LowerDeviceObject, TRUE);
|
||||||
|
USBSTOR_QueueNextRequest(Context->PDODeviceExtension->LowerDeviceObject);
|
||||||
|
|
||||||
|
/* Signal the context event */
|
||||||
|
if (Context->Event)
|
||||||
|
KeSetEvent(Context->Event, 0, FALSE);
|
||||||
|
|
||||||
|
/* Cleanup the IRP context */
|
||||||
|
if (pCDB->AsByte[0] == SCSIOP_READ_CAPACITY)
|
||||||
|
FreeItem(Context->TransferData);
|
||||||
|
FreeItem(Context->cbw);
|
||||||
|
FreeItem(Context);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Stack = IoGetCurrentIrpStackLocation(Context->Irp);
|
|
||||||
//
|
|
||||||
// Retry the operation
|
|
||||||
//
|
|
||||||
Request = (PSCSI_REQUEST_BLOCK)Stack->Parameters.Others.Argument1;
|
|
||||||
DPRINT1("Retrying\n");
|
DPRINT1("Retrying\n");
|
||||||
Status = USBSTOR_HandleExecuteSCSI(DeviceObject, Context->Irp);
|
Status = USBSTOR_HandleExecuteSCSI(DeviceObject, Context->Irp);
|
||||||
|
|
||||||
|
/* Cleanup the old IRP context */
|
||||||
|
if (pCDB->AsByte[0] == SCSIOP_READ_CAPACITY)
|
||||||
|
FreeItem(Context->TransferData);
|
||||||
|
FreeItem(Context->cbw);
|
||||||
|
FreeItem(Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT1("USBSTOR_HandleTransferError returning with Status %x\n", Status);
|
DPRINT1("USBSTOR_HandleTransferError returning with Status %x\n", Status);
|
||||||
|
@ -149,7 +170,7 @@ ErrorHandlerWorkItemRoutine(
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PERRORHANDLER_WORKITEM_DATA WorkItemData = (PERRORHANDLER_WORKITEM_DATA)Context;
|
PERRORHANDLER_WORKITEM_DATA WorkItemData = (PERRORHANDLER_WORKITEM_DATA)Context;
|
||||||
|
|
||||||
Status = USBSTOR_HandleTransferError(WorkItemData->DeviceObject, WorkItemData->Irp, WorkItemData->Context);
|
Status = USBSTOR_HandleTransferError(WorkItemData->DeviceObject, WorkItemData->Context);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Free Work Item Data
|
// Free Work Item Data
|
||||||
|
|
|
@ -181,18 +181,9 @@ USBSTOR_CSWCompletionRoutine(
|
||||||
{
|
{
|
||||||
DPRINT1("Attempting Error Recovery\n");
|
DPRINT1("Attempting Error Recovery\n");
|
||||||
//
|
//
|
||||||
// If a Read Capacity Request free TransferBuffer
|
// free the allocated irp
|
||||||
//
|
//
|
||||||
if (pCDB->AsByte[0] == SCSIOP_READ_CAPACITY)
|
IoFreeIrp(Irp);
|
||||||
{
|
|
||||||
FreeItem(Context->TransferData);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Clean up the rest
|
|
||||||
//
|
|
||||||
FreeItem(Context->cbw);
|
|
||||||
FreeItem(Context);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Allocate Work Item Data
|
// Allocate Work Item Data
|
||||||
|
@ -213,7 +204,6 @@ USBSTOR_CSWCompletionRoutine(
|
||||||
ErrorHandlerWorkItemData);
|
ErrorHandlerWorkItemData);
|
||||||
|
|
||||||
ErrorHandlerWorkItemData->DeviceObject = Context->FDODeviceExtension->FunctionalDeviceObject;
|
ErrorHandlerWorkItemData->DeviceObject = Context->FDODeviceExtension->FunctionalDeviceObject;
|
||||||
ErrorHandlerWorkItemData->Irp = Irp;
|
|
||||||
ErrorHandlerWorkItemData->Context = Context;
|
ErrorHandlerWorkItemData->Context = Context;
|
||||||
DPRINT1("Queuing WorkItemROutine\n");
|
DPRINT1("Queuing WorkItemROutine\n");
|
||||||
ExQueueWorkItem(&ErrorHandlerWorkItemData->WorkQueueItem, DelayedWorkQueue);
|
ExQueueWorkItem(&ErrorHandlerWorkItemData->WorkQueueItem, DelayedWorkQueue);
|
||||||
|
@ -315,6 +305,10 @@ USBSTOR_CSWCompletionRoutine(
|
||||||
KeSetEvent(Context->Event, 0, FALSE);
|
KeSetEvent(Context->Event, 0, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// free our allocated irp
|
||||||
|
//
|
||||||
|
IoFreeIrp(Irp);
|
||||||
|
|
||||||
//
|
//
|
||||||
// free context
|
// free context
|
||||||
|
|
|
@ -278,7 +278,6 @@ typedef struct
|
||||||
typedef struct _ERRORHANDLER_WORKITEM_DATA
|
typedef struct _ERRORHANDLER_WORKITEM_DATA
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
PIRP Irp;
|
|
||||||
PIRP_CONTEXT Context;
|
PIRP_CONTEXT Context;
|
||||||
WORK_QUEUE_ITEM WorkQueueItem;
|
WORK_QUEUE_ITEM WorkQueueItem;
|
||||||
} ERRORHANDLER_WORKITEM_DATA, *PERRORHANDLER_WORKITEM_DATA;
|
} ERRORHANDLER_WORKITEM_DATA, *PERRORHANDLER_WORKITEM_DATA;
|
||||||
|
|
Loading…
Reference in a new issue