[BATTC] Fix comparisons when choosing to complete the status IRP

They were reversed, which meant to immediately complete the IRP
if conditions were NOT satisfied.

Remove a now useless/invalid call to QueryStatus, to return the
status which lead to IRP completion.
This commit is contained in:
Hervé Poussineau 2024-11-16 23:26:51 +01:00
parent 9dedcb67e9
commit 997b1797f4

View file

@ -112,9 +112,9 @@ BatteryClassStatusNotify(PVOID ClassData)
ExAcquireFastMutex(&BattClass->Mutex); ExAcquireFastMutex(&BattClass->Mutex);
if (!(BattWait->PowerState & BattStatus.PowerState) || if (BattWait->PowerState != BattStatus.PowerState ||
(BattWait->HighCapacity > BattStatus.Capacity) || BattWait->HighCapacity < BattStatus.Capacity ||
(BattWait->LowCapacity < BattStatus.Capacity)) BattWait->LowCapacity > BattStatus.Capacity)
{ {
KeSetEvent(&BattClass->WaitEvent, IO_NO_INCREMENT, FALSE); KeSetEvent(&BattClass->WaitEvent, IO_NO_INCREMENT, FALSE);
} }
@ -274,16 +274,15 @@ BatteryClassIoctl(PVOID ClassData,
Timeout.QuadPart = Int32x32To64(BattWait.Timeout, -1000); Timeout.QuadPart = Int32x32To64(BattWait.Timeout, -1000);
BattStatus = Irp->AssociatedIrp.SystemBuffer;
Status = BattClass->MiniportInfo.QueryStatus(BattClass->MiniportInfo.Context, Status = BattClass->MiniportInfo.QueryStatus(BattClass->MiniportInfo.Context,
BattWait.BatteryTag, BattWait.BatteryTag,
(PBATTERY_STATUS)Irp->AssociatedIrp.SystemBuffer); BattStatus);
BattStatus = Irp->AssociatedIrp.SystemBuffer;
if (!NT_SUCCESS(Status) || if (!NT_SUCCESS(Status) ||
((BattWait.PowerState & BattStatus->PowerState) && (BattWait.PowerState == BattStatus->PowerState &&
(BattWait.HighCapacity <= BattStatus->Capacity) && BattWait.HighCapacity >= BattStatus->Capacity &&
(BattWait.LowCapacity >= BattStatus->Capacity))) BattWait.LowCapacity <= BattStatus->Capacity))
{ {
BattNotify.PowerState = BattWait.PowerState; BattNotify.PowerState = BattWait.PowerState;
BattNotify.HighCapacity = BattWait.HighCapacity; BattNotify.HighCapacity = BattWait.HighCapacity;
@ -304,25 +303,14 @@ BatteryClassIoctl(PVOID ClassData,
KernelMode, KernelMode,
FALSE, FALSE,
BattWait.Timeout != -1 ? &Timeout : NULL); BattWait.Timeout != -1 ? &Timeout : NULL);
if (Status == STATUS_TIMEOUT)
Status = STATUS_SUCCESS;
ExAcquireFastMutex(&BattClass->Mutex); ExAcquireFastMutex(&BattClass->Mutex);
BattClass->Waiting = FALSE; BattClass->Waiting = FALSE;
ExReleaseFastMutex(&BattClass->Mutex); ExReleaseFastMutex(&BattClass->Mutex);
BattClass->MiniportInfo.DisableStatusNotify(BattClass->MiniportInfo.Context); BattClass->MiniportInfo.DisableStatusNotify(BattClass->MiniportInfo.Context);
if (Status == STATUS_SUCCESS)
{
Status = BattClass->MiniportInfo.QueryStatus(BattClass->MiniportInfo.Context,
BattWait.BatteryTag,
(PBATTERY_STATUS)Irp->AssociatedIrp.SystemBuffer);
if (NT_SUCCESS(Status))
Irp->IoStatus.Information = sizeof(ULONG);
}
else
{
Status = STATUS_NO_SUCH_DEVICE;
}
} }
else else
{ {