Skip to content

Commit 177a18b

Browse files
committed
[HIDCLASS]
- Call mini driver for pnp events - Wait for all pending irps to complete [HIDUSB] - Fix bug when removing device object found by Cameron Gutman [USBOHCI] - Remove assert - Delete configuration descriptors when device is deleted svn path=/trunk/; revision=55772
1 parent 5429a44 commit 177a18b

File tree

7 files changed

+223
-50
lines changed

7 files changed

+223
-50
lines changed

reactos/drivers/hid/hidclass/fdo.c

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -384,17 +384,21 @@ HidClassFDO_RemoveDevice(
384384
IN PDEVICE_OBJECT DeviceObject,
385385
IN PIRP Irp)
386386
{
387-
PHIDCLASS_FDO_EXTENSION FDODeviceExtension = DeviceObject->DeviceExtension;
388387
NTSTATUS Status;
389388

390-
/* Pass the IRP down */
391-
IoSkipCurrentIrpStackLocation(Irp);
392-
Status = IoCallDriver(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject, Irp);
389+
/* FIXME cleanup */
393390

394-
/* Now teardown our portion of the device stack */
395-
IoDetachDevice(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject);
396-
IoDeleteDevice(DeviceObject);
391+
//
392+
// dispatch to minidriver
393+
//
394+
IoSkipCurrentIrpStackLocation(Irp);
395+
Status = HidClassFDO_DispatchRequestSynchronous(DeviceObject, Irp);
397396

397+
//
398+
// complete request
399+
//
400+
Irp->IoStatus.Status = Status;
401+
IoCompleteRequest(Irp, IO_NO_INCREMENT);
398402
return Status;
399403
}
400404

@@ -533,6 +537,7 @@ HidClassFDO_PnP(
533537
{
534538
PIO_STACK_LOCATION IoStack;
535539
PHIDCLASS_FDO_EXTENSION FDODeviceExtension;
540+
NTSTATUS Status;
536541

537542
//
538543
// get device extension
@@ -554,45 +559,34 @@ HidClassFDO_PnP(
554559
{
555560
return HidClassFDO_RemoveDevice(DeviceObject, Irp);
556561
}
557-
case IRP_MN_QUERY_REMOVE_DEVICE:
558-
case IRP_MN_QUERY_STOP_DEVICE:
562+
case IRP_MN_QUERY_DEVICE_RELATIONS:
559563
{
560-
//
561-
// set status to succes
562-
//
563-
Irp->IoStatus.Status = STATUS_SUCCESS;
564-
565-
//
566-
// forward to lower device
567-
//
568-
IoSkipCurrentIrpStackLocation(Irp);
569-
return IoCallDriver(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject, Irp);
564+
return HidClassFDO_DeviceRelations(DeviceObject, Irp);
570565
}
566+
case IRP_MN_QUERY_REMOVE_DEVICE:
567+
case IRP_MN_QUERY_STOP_DEVICE:
571568
case IRP_MN_CANCEL_REMOVE_DEVICE:
572569
case IRP_MN_CANCEL_STOP_DEVICE:
573570
{
574571
//
575-
// set status to succes
572+
// set status to success and fall through
576573
//
577574
Irp->IoStatus.Status = STATUS_SUCCESS;
578-
579-
//
580-
// forward to lower device
581-
//
582-
IoSkipCurrentIrpStackLocation(Irp);
583-
return IoCallDriver(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject, Irp);
584-
}
585-
case IRP_MN_QUERY_DEVICE_RELATIONS:
586-
{
587-
return HidClassFDO_DeviceRelations(DeviceObject, Irp);
588-
}
575+
}
589576
default:
590577
{
591578
//
592-
// dispatch to lower device
579+
// dispatch to mini driver
593580
//
594-
IoSkipCurrentIrpStackLocation(Irp);
595-
return IoCallDriver(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject, Irp);
581+
IoSkipCurrentIrpStackLocation(Irp);
582+
Status = HidClassFDO_DispatchRequestSynchronous(DeviceObject, Irp);
583+
584+
//
585+
// complete request
586+
//
587+
Irp->IoStatus.Status = Status;
588+
IoCompleteRequest(Irp, IO_NO_INCREMENT);
589+
return Status;
596590
}
597591
}
598592
}

reactos/drivers/hid/hidclass/hidclass.c

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ HidClass_Create(
203203
KeInitializeSpinLock(&Context->Lock);
204204
InitializeListHead(&Context->ReadPendingIrpListHead);
205205
InitializeListHead(&Context->IrpCompletedListHead);
206+
KeInitializeEvent(&Context->IrpReadComplete, NotificationEvent, FALSE);
206207

207208
//
208209
// store context
@@ -226,7 +227,11 @@ HidClass_Close(
226227
{
227228
PIO_STACK_LOCATION IoStack;
228229
PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
229-
PHIDCLASS_IRP_CONTEXT IrpContext;
230+
PHIDCLASS_FILEOP_CONTEXT IrpContext;
231+
BOOLEAN IsRequestPending = FALSE;
232+
KIRQL OldLevel;
233+
PLIST_ENTRY Entry;
234+
PIRP ListIrp;
230235

231236
//
232237
// get device extension
@@ -260,12 +265,79 @@ HidClass_Close(
260265
//
261266
// get irp context
262267
//
263-
IrpContext = (PHIDCLASS_IRP_CONTEXT)IoStack->FileObject->FsContext;
268+
IrpContext = (PHIDCLASS_FILEOP_CONTEXT)IoStack->FileObject->FsContext;
269+
ASSERT(IrpContext);
264270

265271
//
266-
// cancel pending irps
272+
// acquire lock
267273
//
268-
UNIMPLEMENTED
274+
KeAcquireSpinLock(&IrpContext->Lock, &OldLevel);
275+
276+
if (!IsListEmpty(&IrpContext->ReadPendingIrpListHead))
277+
{
278+
//
279+
// FIXME cancel irp
280+
//
281+
IsRequestPending = TRUE;
282+
}
283+
284+
//
285+
// signal stop
286+
//
287+
IrpContext->StopInProgress = TRUE;
288+
289+
//
290+
// release lock
291+
//
292+
KeReleaseSpinLock(&IrpContext->Lock, OldLevel);
293+
294+
if (IsRequestPending)
295+
{
296+
//
297+
// wait for request to complete
298+
//
299+
DPRINT1("[HIDCLASS] Waiting for read irp completion...\n");
300+
KeWaitForSingleObject(&IrpContext->IrpReadComplete, Executive, KernelMode, FALSE, NULL);
301+
}
302+
303+
//
304+
// acquire lock
305+
//
306+
KeAcquireSpinLock(&IrpContext->Lock, &OldLevel);
307+
308+
//
309+
// sanity check
310+
//
311+
ASSERT(IsListEmpty(&IrpContext->ReadPendingIrpListHead));
312+
313+
//
314+
// now free all irps
315+
//
316+
while(!IsListEmpty(&IrpContext->IrpCompletedListHead))
317+
{
318+
//
319+
// remove head irp
320+
//
321+
Entry = RemoveHeadList(&IrpContext->IrpCompletedListHead);
322+
323+
//
324+
// get irp
325+
//
326+
ListIrp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
327+
328+
//
329+
// free the irp
330+
//
331+
IoFreeIrp(ListIrp);
332+
}
333+
334+
//
335+
// release lock
336+
//
337+
KeReleaseSpinLock(&IrpContext->Lock, OldLevel);
338+
339+
340+
269341

270342
//
271343
// remove context
@@ -323,19 +395,20 @@ HidClass_ReadCompleteIrp(
323395
ULONG Offset;
324396
PHIDP_COLLECTION_DESC CollectionDescription;
325397
PHIDP_REPORT_IDS ReportDescription;
398+
BOOLEAN IsEmpty;
326399

327400
//
328401
// get irp context
329402
//
330403
IrpContext = (PHIDCLASS_IRP_CONTEXT)Ctx;
331404

332-
DPRINT("HidClass_ReadCompleteIrp Irql %lu\n", KeGetCurrentIrql());
333-
DPRINT("HidClass_ReadCompleteIrp Status %lx\n", Irp->IoStatus.Status);
334-
DPRINT("HidClass_ReadCompleteIrp Length %lu\n", Irp->IoStatus.Information);
335-
DPRINT("HidClass_ReadCompleteIrp Irp %p\n", Irp);
336-
DPRINT("HidClass_ReadCompleteIrp InputReportBuffer %p\n", IrpContext->InputReportBuffer);
337-
DPRINT("HidClass_ReadCompleteIrp InputReportBufferLength %li\n", IrpContext->InputReportBufferLength);
338-
DPRINT("HidClass_ReadCompleteIrp OriginalIrp %p\n", IrpContext->OriginalIrp);
405+
DPRINT1("HidClass_ReadCompleteIrp Irql %lu\n", KeGetCurrentIrql());
406+
DPRINT1("HidClass_ReadCompleteIrp Status %lx\n", Irp->IoStatus.Status);
407+
DPRINT1("HidClass_ReadCompleteIrp Length %lu\n", Irp->IoStatus.Information);
408+
DPRINT1("HidClass_ReadCompleteIrp Irp %p\n", Irp);
409+
DPRINT1("HidClass_ReadCompleteIrp InputReportBuffer %p\n", IrpContext->InputReportBuffer);
410+
DPRINT1("HidClass_ReadCompleteIrp InputReportBufferLength %li\n", IrpContext->InputReportBufferLength);
411+
DPRINT1("HidClass_ReadCompleteIrp OriginalIrp %p\n", IrpContext->OriginalIrp);
339412

340413
//
341414
// copy result
@@ -402,6 +475,11 @@ HidClass_ReadCompleteIrp(
402475
//
403476
RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
404477

478+
//
479+
// is list empty
480+
//
481+
IsEmpty = IsListEmpty(&IrpContext->FileOp->ReadPendingIrpListHead);
482+
405483
//
406484
// insert into completed list
407485
//
@@ -417,6 +495,17 @@ HidClass_ReadCompleteIrp(
417495
//
418496
IoCompleteRequest(IrpContext->OriginalIrp, IO_NO_INCREMENT);
419497

498+
499+
DPRINT1("StopInProgress %x IsEmpty %x\n", IrpContext->FileOp->StopInProgress, IsEmpty);
500+
if (IrpContext->FileOp->StopInProgress && IsEmpty)
501+
{
502+
//
503+
// last pending irp
504+
//
505+
DPRINT1("[HIDCLASS] LastPendingTransfer Signalling\n");
506+
KeSetEvent(&IrpContext->FileOp->IrpReadComplete, 0, FALSE);
507+
}
508+
420509
//
421510
// free irp context
422511
//
@@ -644,6 +733,19 @@ HidClass_Read(
644733
//
645734
ASSERT(Context->DeviceExtension->Common.DriverExtension->DevicesArePolled == FALSE);
646735

736+
if (Context->StopInProgress)
737+
{
738+
//
739+
// stop in progress
740+
//
741+
DPRINT1("[HIDCLASS] Stop In Progress\n");
742+
Irp->IoStatus.Status = STATUS_CANCELLED;
743+
IoCompleteRequest(Irp, IO_NO_INCREMENT);
744+
return STATUS_CANCELLED;
745+
746+
}
747+
748+
647749
//
648750
// build irp request
649751
//

reactos/drivers/hid/hidclass/precomp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ typedef struct __HIDCLASS_FILEOP_CONTEXT__
136136
//
137137
LIST_ENTRY IrpCompletedListHead;
138138

139+
//
140+
// stop in progress indicator
141+
//
142+
BOOLEAN StopInProgress;
143+
144+
//
145+
// read complete event
146+
//
147+
KEVENT IrpReadComplete;
148+
139149
}HIDCLASS_FILEOP_CONTEXT, *PHIDCLASS_FILEOP_CONTEXT;
140150

141151
typedef struct

reactos/drivers/hid/hidusb/hidusb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,10 +1576,10 @@ HidPnp(
15761576
//
15771577
// free resources
15781578
//
1579-
if (HidDeviceExtension->HidDescriptor)
1579+
if (HidDeviceExtension->ConfigurationDescriptor)
15801580
{
1581-
ExFreePool(HidDeviceExtension->HidDescriptor);
1582-
HidDeviceExtension->HidDescriptor = NULL;
1581+
ExFreePool(HidDeviceExtension->ConfigurationDescriptor);
1582+
HidDeviceExtension->ConfigurationDescriptor = NULL;
15831583
}
15841584

15851585
//

reactos/drivers/hid/hidusb/hidusb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef struct
4545
// hid descriptor
4646
//
4747
PHID_DESCRIPTOR HidDescriptor;
48+
4849
}HID_USB_DEVICE_EXTENSION, *PHID_USB_DEVICE_EXTENSION;
4950

5051
typedef struct

reactos/drivers/usb/usbohci/hub_controller.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,6 @@ CHubController::HandleClassOther(
10121012
// reset port feature
10131013
//
10141014
Status = m_Hardware->SetPortFeature(PortId, PORT_RESET);
1015-
PC_ASSERT(Status == STATUS_SUCCESS);
10161015
break;
10171016
}
10181017
default:

0 commit comments

Comments
 (0)