From ed23d5951d1b298eb6c0d81381035e18ee5e3b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Wed, 4 May 2005 13:28:34 +0000 Subject: [PATCH] Fix flags checking in I8042ReadData (patch by Tinus_) Check error codes returned by IoCreateDevice Replace ExFreePool by ExFreePoolWithTag svn path=/trunk/; revision=14967 --- reactos/drivers/input/i8042prt/i8042prt.c | 92 +++++++++++++---------- reactos/drivers/input/i8042prt/registry.c | 2 +- 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/reactos/drivers/input/i8042prt/i8042prt.c b/reactos/drivers/input/i8042prt/i8042prt.c index 83d4454beba..0e6455f5be9 100644 --- a/reactos/drivers/input/i8042prt/i8042prt.c +++ b/reactos/drivers/input/i8042prt/i8042prt.c @@ -80,9 +80,10 @@ NTSTATUS I8042ReadData(BYTE *Data) // If data is available if ((Status & KBD_OBF)) { Data[0]=READ_PORT_UCHAR((PUCHAR)I8042_DATA_PORT); + DPRINT("Read: %x (status: %x)\n", Data[0], Status); // If the data is valid (not timeout, not parity error) - if ((~Status) & (KBD_GTO | KBD_PERR)) + if (0 == (Status & (KBD_GTO | KBD_PERR))) return STATUS_SUCCESS; } return STATUS_UNSUCCESSFUL; @@ -613,7 +614,7 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject, DPRINT("I8042AddDevice\n"); - IoCreateDevice(DriverObject, + Status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_8042_PORT, @@ -621,6 +622,9 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject, TRUE, &Fdo); + if (!NT_SUCCESS(Status)) + return Status; + IoAttachDeviceToDeviceStack(Fdo, Pdo); DevExt = Fdo->DeviceExtension; @@ -647,7 +651,7 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject, KeInitializeTimer(&DevExt->TimerMouseTimeout); Status = I8042Initialize(DevExt); - if (STATUS_SUCCESS != Status) { + if (!NT_SUCCESS(STATUS_SUCCESS)) { DPRINT1("Initialization failure: %x\n", Status); return Status; } @@ -668,31 +672,36 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject, TRUE, &Fdo); - FdoDevExt = Fdo->DeviceExtension; + if (NT_SUCCESS(Status)) + { + FdoDevExt = Fdo->DeviceExtension; - RtlZeroMemory(FdoDevExt, sizeof(FDO_DEVICE_EXTENSION)); + RtlZeroMemory(FdoDevExt, sizeof(FDO_DEVICE_EXTENSION)); - FdoDevExt->PortDevExt = DevExt; - FdoDevExt->Type = Keyboard; - FdoDevExt->DeviceObject = Fdo; + FdoDevExt->PortDevExt = DevExt; + FdoDevExt->Type = Keyboard; + FdoDevExt->DeviceObject = Fdo; - Fdo->Flags |= DO_BUFFERED_IO; + Fdo->Flags |= DO_BUFFERED_IO; - DevExt->DebugWorkItem = IoAllocateWorkItem(Fdo); - DevExt->KeyboardObject = Fdo; + DevExt->DebugWorkItem = IoAllocateWorkItem(Fdo); + DevExt->KeyboardObject = Fdo; - DevExt->KeyboardBuffer = ExAllocatePoolWithTag( - NonPagedPool, - DevExt->KeyboardAttributes.InputDataQueueLength * - sizeof(KEYBOARD_INPUT_DATA), - TAG_I8042); + DevExt->KeyboardBuffer = ExAllocatePoolWithTag( + NonPagedPool, + DevExt->KeyboardAttributes.InputDataQueueLength * + sizeof(KEYBOARD_INPUT_DATA), + TAG_I8042); - if (!DevExt->KeyboardBuffer) { - DPRINT1("No memory for keyboardbuffer\n"); - return STATUS_INSUFFICIENT_RESOURCES; + if (!DevExt->KeyboardBuffer) { + DPRINT1("No memory for keyboardbuffer\n"); + return STATUS_INSUFFICIENT_RESOURCES; + } + + InsertTailList(&DevExt->BusDevices, &FdoDevExt->BusDevices); } - - InsertTailList(&DevExt->BusDevices, &FdoDevExt->BusDevices); + else + DevExt->KeyboardExists = FALSE; } if (DevExt->MouseExists) { @@ -711,30 +720,35 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject, TRUE, &Fdo); - FdoDevExt = Fdo->DeviceExtension; + if (NT_SUCCESS(Status)) + { + FdoDevExt = Fdo->DeviceExtension; - RtlZeroMemory(FdoDevExt, sizeof(FDO_DEVICE_EXTENSION)); + RtlZeroMemory(FdoDevExt, sizeof(FDO_DEVICE_EXTENSION)); - FdoDevExt->PortDevExt = DevExt; - FdoDevExt->Type = Mouse; - FdoDevExt->DeviceObject = Fdo; + FdoDevExt->PortDevExt = DevExt; + FdoDevExt->Type = Mouse; + FdoDevExt->DeviceObject = Fdo; - Fdo->Flags |= DO_BUFFERED_IO; - DevExt->MouseObject = Fdo; + Fdo->Flags |= DO_BUFFERED_IO; + DevExt->MouseObject = Fdo; + + DevExt->MouseBuffer = ExAllocatePoolWithTag( + NonPagedPool, + DevExt->MouseAttributes.InputDataQueueLength * + sizeof(MOUSE_INPUT_DATA), + TAG_I8042); - DevExt->MouseBuffer = ExAllocatePoolWithTag( - NonPagedPool, - DevExt->MouseAttributes.InputDataQueueLength * - sizeof(MOUSE_INPUT_DATA), - TAG_I8042); + if (!DevExt->MouseBuffer) { + ExFreePoolWithTag(DevExt->KeyboardBuffer, TAG_I8042); + DPRINT1("No memory for mouse buffer\n"); + return STATUS_INSUFFICIENT_RESOURCES; + } - if (!DevExt->MouseBuffer) { - ExFreePool(DevExt->KeyboardBuffer); - DPRINT1("No memory for mouse buffer\n"); - return STATUS_INSUFFICIENT_RESOURCES; + InsertTailList(&DevExt->BusDevices, &FdoDevExt->BusDevices); } - - InsertTailList(&DevExt->BusDevices, &FdoDevExt->BusDevices); + else + DevExt->MouseExists = FALSE; } if (DirqlKeyboard > DirqlMouse) diff --git a/reactos/drivers/input/i8042prt/registry.c b/reactos/drivers/input/i8042prt/registry.c index d71d99a6056..ad274d64342 100644 --- a/reactos/drivers/input/i8042prt/registry.c +++ b/reactos/drivers/input/i8042prt/registry.c @@ -231,7 +231,7 @@ VOID STDCALL I8042ReadRegistry(PDRIVER_OBJECT DriverObject, DPRINT1 ("Manually set defaults\n"); } - ExFreePool(ParametersPath.Buffer); + ExFreePoolWithTag(ParametersPath.Buffer, TAG_I8042); DPRINT("Done reading registry\n"); }