From b546b6d0b289349ad4380f113a7b6b0742d8aa02 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Wed, 22 Dec 2010 18:53:08 +0000 Subject: [PATCH] [KS] - Add sanity checks - Acquire device entry lock before dealing with device entries - Fix acquiring bus device extension for parent bus device object - Store result in irp io status block - get install interface from assoicated system buffer - Fixes install of new audio devices with ros ks in windows - Tested with VBOX 3.2.10+WINXP+SP3 svn path=/branches/audio-bringup/; revision=50104 --- drivers/ksfilter/ks/filter.c | 1 - drivers/ksfilter/ks/swenum.c | 29 ++++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/ksfilter/ks/filter.c b/drivers/ksfilter/ks/filter.c index 6c80bf9f0c3..fe20361f1a1 100644 --- a/drivers/ksfilter/ks/filter.c +++ b/drivers/ksfilter/ks/filter.c @@ -1858,7 +1858,6 @@ KsFilterAttemptProcessing( if (!KsGateCaptureThreshold(Gate)) { /* filter control gate is closed */ - DPRINT1("Gate %p Closed %x\n", Gate, Gate->Count); return; } DPRINT1("processing\n"); diff --git a/drivers/ksfilter/ks/swenum.c b/drivers/ksfilter/ks/swenum.c index d764ed9a88d..08d5286bd58 100644 --- a/drivers/ksfilter/ks/swenum.c +++ b/drivers/ksfilter/ks/swenum.c @@ -973,6 +973,9 @@ KspInstallInterface( NTSTATUS Status; OBJECT_ATTRIBUTES ObjectAttributes; + /* sanity check */ + ASSERT(InstallInterface); + /* calculate length */ Length = wcslen(InstallInterface->ReferenceString); @@ -1059,13 +1062,18 @@ KspInstallBusEnumInterface( PLIST_ENTRY Entry; PBUS_DEVICE_ENTRY DeviceEntry; PSWENUM_INSTALL_INTERFACE InstallInterface; + KIRQL OldLevel; PBUS_INSTALL_ENUM_CONTEXT Context = (PBUS_INSTALL_ENUM_CONTEXT)Ctx; /* get current irp stack location */ IoStack = IoGetCurrentIrpStackLocation(Context->Irp); /* get install request */ - InstallInterface = (PSWENUM_INSTALL_INTERFACE)IoStack->Parameters.DeviceIoControl.Type3InputBuffer; + InstallInterface = (PSWENUM_INSTALL_INTERFACE)Context->Irp->AssociatedIrp.SystemBuffer; + + /* sanity check */ + ASSERT(InstallInterface); + ASSERT(Context->BusDeviceExtension); if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(SWENUM_INSTALL_INTERFACE)) { @@ -1095,6 +1103,9 @@ KspInstallBusEnumInterface( return; } + /* acquire device entry lock */ + KeAcquireSpinLock(&Context->BusDeviceExtension->Lock, &OldLevel); + /* now iterate all device entries */ Entry = Context->BusDeviceExtension->Common.Entry.Flink; while(Entry != &Context->BusDeviceExtension->Common.Entry) @@ -1114,8 +1125,14 @@ KspInstallBusEnumInterface( break; } } + + /* move to next entry */ + Entry = Entry->Flink; } + /* release device entry lock */ + KeReleaseSpinLock(&Context->BusDeviceExtension->Lock, OldLevel); + /* signal that bus driver relations has changed */ IoInvalidateDeviceRelations(Context->BusDeviceExtension->PhysicalDeviceObject, BusRelations); @@ -1364,7 +1381,7 @@ KsGetBusEnumIdentifier( DeviceExtension = (PDEV_EXTENSION)IoStack->DeviceObject->DeviceExtension; /* get bus device extension */ - BusDeviceExtension = (PBUS_ENUM_DEVICE_EXTENSION)DeviceExtension->Ext->BusDeviceExtension; + BusDeviceExtension = (PBUS_ENUM_DEVICE_EXTENSION)DeviceExtension->Ext; /* sanity checks */ ASSERT(BusDeviceExtension); @@ -1715,7 +1732,7 @@ KsInstallBusEnumInterface( PDEV_EXTENSION DeviceExtension; PBUS_ENUM_DEVICE_EXTENSION BusDeviceExtension; - DPRINT1("KsGetBusEnumPnpDeviceObject\n"); + DPRINT1("KsInstallBusEnumInterface\n"); /* get current irp stack location */ IoStack = IoGetCurrentIrpStackLocation(Irp); @@ -1737,7 +1754,7 @@ KsInstallBusEnumInterface( DeviceExtension = (PDEV_EXTENSION)IoStack->DeviceObject->DeviceExtension; /* get bus device extension */ - BusDeviceExtension = DeviceExtension->Ext->BusDeviceExtension; + BusDeviceExtension = (PBUS_ENUM_DEVICE_EXTENSION)DeviceExtension->Ext; /* initialize context */ @@ -1748,10 +1765,12 @@ KsInstallBusEnumInterface( /* queue the work item */ ExQueueWorkItem(&Context.WorkItem, DelayedWorkQueue); - /* wait for completion */ KeWaitForSingleObject(&Context.Event, Executive, KernelMode, FALSE, NULL); + /* store result */ + Irp->IoStatus.Status = Context.Status; + /* done */ return Context.Status; }