From a485607cfc0cc762e6ce220cd6b326852f3472e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Tue, 8 Nov 2005 16:24:58 +0000 Subject: [PATCH] =?UTF-8?q?Patch=20by=20Filip=20Navara/Herv=C3=A9=20Poussi?= =?UTF-8?q?neau:=20-=20Simplify=20device=20number=20allocation=20-=20Check?= =?UTF-8?q?=20the=20case=20of=20a=20NULL=20Pdo=20if=20we're=20called=20by?= =?UTF-8?q?=20a=20legacy=20driver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit svn path=/trunk/; revision=19054 --- reactos/drivers/video/videoprt/dispatch.c | 15 +++++++-- reactos/drivers/video/videoprt/videoprt.c | 38 ++--------------------- 2 files changed, 15 insertions(+), 38 deletions(-) diff --git a/reactos/drivers/video/videoprt/dispatch.c b/reactos/drivers/video/videoprt/dispatch.c index 5d05ba222bd..28545a23034 100644 --- a/reactos/drivers/video/videoprt/dispatch.c +++ b/reactos/drivers/video/videoprt/dispatch.c @@ -68,6 +68,8 @@ IntVideoPortAddDevice( IN PDEVICE_OBJECT PhysicalDeviceObject) { PVIDEO_PORT_DRIVER_EXTENSION DriverExtension; + PDEVICE_OBJECT DeviceObject; + NTSTATUS Status; /* * Get the initialization data we saved in VideoPortInitialize. @@ -79,11 +81,20 @@ IntVideoPortAddDevice( * Create adapter device object. */ - return IntVideoPortCreateAdapterDeviceObject( + Status = IntVideoPortCreateAdapterDeviceObject( DriverObject, DriverExtension, PhysicalDeviceObject, - NULL); + &DeviceObject); + if (!NT_SUCCESS(Status)) + return Status; + + if (PhysicalDeviceObject == NULL) + { + /* We will never have a IRP_MJ_PNP/IRP_MN_START_DEVICE Irp */ + Status = IntVideoPortFindAdapter(DriverObject, DriverExtension, DeviceObject); + } + return Status; } /* diff --git a/reactos/drivers/video/videoprt/videoprt.c b/reactos/drivers/video/videoprt/videoprt.c index 6c1dbac1b18..19f10f96555 100644 --- a/reactos/drivers/video/videoprt/videoprt.c +++ b/reactos/drivers/video/videoprt/videoprt.c @@ -27,6 +27,7 @@ ULONG CsrssInitialized = FALSE; PKPROCESS Csrss = NULL; +ULONG VideoPortDeviceNumber = 0; /* PRIVATE FUNCTIONS **********************************************************/ @@ -128,41 +129,6 @@ IntVideoPortDeferredRoutine( ((PMINIPORT_DPC_ROUTINE)SystemArgument1)(HwDeviceExtension, SystemArgument2); } -ULONG NTAPI -IntVideoPortAllocateDeviceNumber(VOID) -{ - NTSTATUS Status; - ULONG DeviceNumber; - WCHAR SymlinkBuffer[20]; - UNICODE_STRING SymlinkName; - - for (DeviceNumber = 0;;) - { - OBJECT_ATTRIBUTES Obj; - HANDLE ObjHandle; - - swprintf(SymlinkBuffer, L"\\??\\DISPLAY%lu", DeviceNumber + 1); - RtlInitUnicodeString(&SymlinkName, SymlinkBuffer); - InitializeObjectAttributes(&Obj, &SymlinkName, 0, NULL, NULL); - Status = ZwOpenSymbolicLinkObject(&ObjHandle, GENERIC_READ, &Obj); - if (NT_SUCCESS(Status)) - { - ZwClose(ObjHandle); - DeviceNumber++; - continue; - } - else if (Status == STATUS_OBJECT_NAME_NOT_FOUND) - break; - else - { - DPRINT1("ZwOpenSymbolicLinkObject() returned unexpected status: 0x%08lx\n", Status); - return 0xFFFFFFFF; - } - } - - return DeviceNumber; -} - NTSTATUS NTAPI IntVideoPortCreateAdapterDeviceObject( IN PDRIVER_OBJECT DriverObject, @@ -186,7 +152,7 @@ IntVideoPortCreateAdapterDeviceObject( * object names and symlinks. */ - DeviceNumber = IntVideoPortAllocateDeviceNumber(); + DeviceNumber = VideoPortDeviceNumber++; if (DeviceNumber == 0xFFFFFFFF) { DPRINT("Can't find free device number\n");