Fix flags checking in I8042ReadData (patch by Tinus_)

Check error codes returned by IoCreateDevice
Replace ExFreePool by ExFreePoolWithTag

svn path=/trunk/; revision=14967
This commit is contained in:
Hervé Poussineau 2005-05-04 13:28:34 +00:00
parent 985abe1494
commit ed23d5951d
2 changed files with 54 additions and 40 deletions

View file

@ -80,9 +80,10 @@ NTSTATUS I8042ReadData(BYTE *Data)
// If data is available // If data is available
if ((Status & KBD_OBF)) { if ((Status & KBD_OBF)) {
Data[0]=READ_PORT_UCHAR((PUCHAR)I8042_DATA_PORT); 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 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_SUCCESS;
} }
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
@ -613,7 +614,7 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject,
DPRINT("I8042AddDevice\n"); DPRINT("I8042AddDevice\n");
IoCreateDevice(DriverObject, Status = IoCreateDevice(DriverObject,
sizeof(DEVICE_EXTENSION), sizeof(DEVICE_EXTENSION),
NULL, NULL,
FILE_DEVICE_8042_PORT, FILE_DEVICE_8042_PORT,
@ -621,6 +622,9 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject,
TRUE, TRUE,
&Fdo); &Fdo);
if (!NT_SUCCESS(Status))
return Status;
IoAttachDeviceToDeviceStack(Fdo, Pdo); IoAttachDeviceToDeviceStack(Fdo, Pdo);
DevExt = Fdo->DeviceExtension; DevExt = Fdo->DeviceExtension;
@ -647,7 +651,7 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject,
KeInitializeTimer(&DevExt->TimerMouseTimeout); KeInitializeTimer(&DevExt->TimerMouseTimeout);
Status = I8042Initialize(DevExt); Status = I8042Initialize(DevExt);
if (STATUS_SUCCESS != Status) { if (!NT_SUCCESS(STATUS_SUCCESS)) {
DPRINT1("Initialization failure: %x\n", Status); DPRINT1("Initialization failure: %x\n", Status);
return Status; return Status;
} }
@ -668,31 +672,36 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject,
TRUE, TRUE,
&Fdo); &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->PortDevExt = DevExt;
FdoDevExt->Type = Keyboard; FdoDevExt->Type = Keyboard;
FdoDevExt->DeviceObject = Fdo; FdoDevExt->DeviceObject = Fdo;
Fdo->Flags |= DO_BUFFERED_IO; Fdo->Flags |= DO_BUFFERED_IO;
DevExt->DebugWorkItem = IoAllocateWorkItem(Fdo); DevExt->DebugWorkItem = IoAllocateWorkItem(Fdo);
DevExt->KeyboardObject = Fdo; DevExt->KeyboardObject = Fdo;
DevExt->KeyboardBuffer = ExAllocatePoolWithTag( DevExt->KeyboardBuffer = ExAllocatePoolWithTag(
NonPagedPool, NonPagedPool,
DevExt->KeyboardAttributes.InputDataQueueLength * DevExt->KeyboardAttributes.InputDataQueueLength *
sizeof(KEYBOARD_INPUT_DATA), sizeof(KEYBOARD_INPUT_DATA),
TAG_I8042); TAG_I8042);
if (!DevExt->KeyboardBuffer) { if (!DevExt->KeyboardBuffer) {
DPRINT1("No memory for keyboardbuffer\n"); DPRINT1("No memory for keyboardbuffer\n");
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
}
InsertTailList(&DevExt->BusDevices, &FdoDevExt->BusDevices);
} }
else
InsertTailList(&DevExt->BusDevices, &FdoDevExt->BusDevices); DevExt->KeyboardExists = FALSE;
} }
if (DevExt->MouseExists) { if (DevExt->MouseExists) {
@ -711,30 +720,35 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject,
TRUE, TRUE,
&Fdo); &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->PortDevExt = DevExt;
FdoDevExt->Type = Mouse; FdoDevExt->Type = Mouse;
FdoDevExt->DeviceObject = Fdo; FdoDevExt->DeviceObject = Fdo;
Fdo->Flags |= DO_BUFFERED_IO; Fdo->Flags |= DO_BUFFERED_IO;
DevExt->MouseObject = Fdo; DevExt->MouseObject = Fdo;
DevExt->MouseBuffer = ExAllocatePoolWithTag(
NonPagedPool,
DevExt->MouseAttributes.InputDataQueueLength *
sizeof(MOUSE_INPUT_DATA),
TAG_I8042);
DevExt->MouseBuffer = ExAllocatePoolWithTag( if (!DevExt->MouseBuffer) {
NonPagedPool, ExFreePoolWithTag(DevExt->KeyboardBuffer, TAG_I8042);
DevExt->MouseAttributes.InputDataQueueLength * DPRINT1("No memory for mouse buffer\n");
sizeof(MOUSE_INPUT_DATA), return STATUS_INSUFFICIENT_RESOURCES;
TAG_I8042); }
if (!DevExt->MouseBuffer) { InsertTailList(&DevExt->BusDevices, &FdoDevExt->BusDevices);
ExFreePool(DevExt->KeyboardBuffer);
DPRINT1("No memory for mouse buffer\n");
return STATUS_INSUFFICIENT_RESOURCES;
} }
else
InsertTailList(&DevExt->BusDevices, &FdoDevExt->BusDevices); DevExt->MouseExists = FALSE;
} }
if (DirqlKeyboard > DirqlMouse) if (DirqlKeyboard > DirqlMouse)

View file

@ -231,7 +231,7 @@ VOID STDCALL I8042ReadRegistry(PDRIVER_OBJECT DriverObject,
DPRINT1 ("Manually set defaults\n"); DPRINT1 ("Manually set defaults\n");
} }
ExFreePool(ParametersPath.Buffer); ExFreePoolWithTag(ParametersPath.Buffer, TAG_I8042);
DPRINT("Done reading registry\n"); DPRINT("Done reading registry\n");
} }