[BATTC] Check if MiniportInfo->Pdo is NULL before passing it to IoRegisterDeviceInterface

[CMBATT] Fix broken CmBattGetAcpiInterfaces
[COMPBATT] Fix "typo" in CompBattAddDevice that caused memory corruption

svn path=/trunk/; revision=61628
This commit is contained in:
Timo Kreuzer 2014-01-14 21:21:29 +00:00
parent fa95b5794c
commit 1ea1ab9f88
4 changed files with 186 additions and 116 deletions

View file

@ -151,18 +151,26 @@ BatteryClassInitializeDevice(PBATTERY_MINIPORT_INFO MiniportInfo,
ExInitializeFastMutex(&BattClass->Mutex);
Status = IoRegisterDeviceInterface(MiniportInfo->Pdo,
&GUID_DEVICE_BATTERY,
NULL,
&BattClass->InterfaceName);
if (NT_SUCCESS(Status))
if (MiniportInfo->Pdo != NULL)
{
DPRINT("Initialized battery interface: %wZ\n", &BattClass->InterfaceName);
IoSetDeviceInterfaceState(&BattClass->InterfaceName, TRUE);
}
else
{
DPRINT1("IoRegisterDeviceInterface failed (0x%x)\n", Status);
Status = IoRegisterDeviceInterface(MiniportInfo->Pdo,
&GUID_DEVICE_BATTERY,
NULL,
&BattClass->InterfaceName);
if (NT_SUCCESS(Status))
{
DPRINT("Initialized battery interface: %wZ\n", &BattClass->InterfaceName);
Status = IoSetDeviceInterfaceState(&BattClass->InterfaceName, TRUE);
if (Status == STATUS_OBJECT_NAME_EXISTS)
{
DPRINT1("Got STATUS_OBJECT_NAME_EXISTS for SetDeviceInterfaceState\n");
Status = STATUS_SUCCESS;
}
}
else
{
DPRINT1("IoRegisterDeviceInterface failed (0x%x)\n", Status);
}
}
*ClassData = BattClass;

View file

@ -87,6 +87,7 @@ CmBattGetAcpiInterfaces(IN PDEVICE_OBJECT DeviceObject,
/* Build the query */
IoStackLocation = IoGetNextIrpStackLocation(Irp);
IoStackLocation->MajorFunction = IRP_MJ_PNP;
IoStackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE;
IoStackLocation->Parameters.QueryInterface.InterfaceType = &GUID_ACPI_INTERFACE_STANDARD;
IoStackLocation->Parameters.QueryInterface.Size = sizeof(ACPI_INTERFACE_STANDARD);
@ -102,7 +103,6 @@ CmBattGetAcpiInterfaces(IN PDEVICE_OBJECT DeviceObject,
KeInitializeEvent(&Event, SynchronizationEvent, 0);
/* Set the completion routine */
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp,
(PVOID)CmBattIoCompletion,
&Event,
@ -276,7 +276,7 @@ CmBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
Status = STATUS_NOT_SUPPORTED;
/* Try to acquire the lock before doing anything */
Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, 0);
Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
if (!NT_SUCCESS(Status))
{
/* Complete the request */
@ -604,7 +604,7 @@ CmBattCreateFdo(IN PDRIVER_OBJECT DriverObject,
/* Setup the rest of the extension */
ExInitializeFastMutex(&FdoExtension->FastMutex);
IoInitializeRemoveLock(&FdoExtension->RemoveLock, 0, 0, 0);
IoInitializeRemoveLock(&FdoExtension->RemoveLock, 'RbmC', 0, 0);
FdoExtension->HandleCount = 0;
FdoExtension->WaitWakeEnable = FALSE;
FdoExtension->DeviceId = UniqueId;
@ -630,7 +630,7 @@ CmBattCreateFdo(IN PDRIVER_OBJECT DriverObject,
if (NT_SUCCESS(Status))
{
/* Set value */
FdoExtension->WaitWakeEnable = *(PULONG)PartialInfo->Data;
FdoExtension->WaitWakeEnable = ((*(PULONG)PartialInfo->Data) != 0);
}
/* Close the handle */

View file

@ -343,7 +343,7 @@ CompBattAddDevice(IN PDRIVER_OBJECT DriverObject,
/* Initialize the device extension */
DeviceExtension = DeviceObject->DeviceExtension;
RtlZeroMemory(DeviceExtension, 0x1B0u);
RtlZeroMemory(DeviceExtension, sizeof(COMPBATT_DEVICE_EXTENSION));
/* Attach to device stack and set DO pointers */
DeviceExtension->AttachedDevice = IoAttachDeviceToDeviceStack(DeviceObject,

View file

@ -353,6 +353,63 @@ PciIdeXPdoQueryDeviceRelations(
return STATUS_SUCCESS;
}
//GUID_PCIIDE_INTERRUPT_INTERFACE
//GUID_PCIIDE_REQUEST_PROPER_RESOURCES
DEFINE_GUID(GUID_PCIIDE_SYNC_ACCESS_INTERFACE, 0x681190EB, 0xE4EA, 0x11D0, 0xAB, 0x82, 0x00, 0xA0, 0xC9, 0x06, 0x96, 0x2F);
DEFINE_GUID(GUID_PCIIDE_XFER_MODE_INTERFACE, 0x681190EC, 0xE4EA, 0x11D0, 0xAB, 0x82, 0x00, 0xA0, 0xC9, 0x06, 0x96, 0x2F);
NTSTATUS
PciIdeXPdoPnpQueryInterface(
PIRP Irp)
{
#if 0
PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
PACPI_INTERFACE_STANDARD AcpiInterface;
if (IrpStack->Parameters.QueryInterface.Version != 1)
{
DPRINT1("Invalid version number: %d\n",
IrpStack->Parameters.QueryInterface.Version);
return STATUS_INVALID_PARAMETER;
}
if (IsEqualGUID(IrpStack->Parameters.QueryInterface.InterfaceType,
&GUID_PCIIDE_XFER_MODE_INTERFACE))
{
DPRINT1("GUID_PCIIDE_XFER_MODE_INTERFACE\n");
if (IrpStack->Parameters.QueryInterface.Size < sizeof(ACPI_INTERFACE_STANDARD))
{
DPRINT1("Buffer too small! (%d)\n", IrpStack->Parameters.QueryInterface.Size);
return STATUS_BUFFER_TOO_SMALL;
}
AcpiInterface = (PACPI_INTERFACE_STANDARD)IrpStack->Parameters.QueryInterface.Interface;
AcpiInterface->InterfaceReference = AcpiInterfaceReference;
AcpiInterface->InterfaceDereference = AcpiInterfaceDereference;
AcpiInterface->GpeConnectVector = AcpiInterfaceConnectVector;
AcpiInterface->GpeDisconnectVector = AcpiInterfaceDisconnectVector;
AcpiInterface->GpeEnableEvent = AcpiInterfaceEnableEvent;
AcpiInterface->GpeDisableEvent = AcpiInterfaceDisableEvent;
AcpiInterface->GpeClearStatus = AcpiInterfaceClearStatus;
AcpiInterface->RegisterForDeviceNotifications = AcpiInterfaceNotificationsRegister;
AcpiInterface->UnregisterForDeviceNotifications = AcpiInterfaceNotificationsUnregister;
return STATUS_SUCCESS;
}
else
{
DPRINT1("Invalid GUID\n");
return STATUS_NOT_SUPPORTED;
}
#endif
return STATUS_NOT_IMPLEMENTED;
}
NTSTATUS NTAPI
PciIdeXPdoPnpDispatch(
IN PDEVICE_OBJECT DeviceObject,
@ -519,6 +576,11 @@ PciIdeXPdoPnpDispatch(
}
break;
}
case IRP_MN_QUERY_INTERFACE:
{
Status = PciIdeXPdoPnpQueryInterface(Irp);
break;
}
default:
{
/* We can't forward request to the lower driver, because