From 997b1797f4a90360f6113265701245814bf3f934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Sat, 16 Nov 2024 23:26:51 +0100 Subject: [PATCH] [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. --- drivers/battery/battc/battc.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/drivers/battery/battc/battc.c b/drivers/battery/battc/battc.c index 8ddacd64359..dd08a9cd956 100644 --- a/drivers/battery/battc/battc.c +++ b/drivers/battery/battc/battc.c @@ -112,9 +112,9 @@ BatteryClassStatusNotify(PVOID ClassData) ExAcquireFastMutex(&BattClass->Mutex); - if (!(BattWait->PowerState & BattStatus.PowerState) || - (BattWait->HighCapacity > BattStatus.Capacity) || - (BattWait->LowCapacity < BattStatus.Capacity)) + if (BattWait->PowerState != BattStatus.PowerState || + BattWait->HighCapacity < BattStatus.Capacity || + BattWait->LowCapacity > BattStatus.Capacity) { KeSetEvent(&BattClass->WaitEvent, IO_NO_INCREMENT, FALSE); } @@ -274,16 +274,15 @@ BatteryClassIoctl(PVOID ClassData, Timeout.QuadPart = Int32x32To64(BattWait.Timeout, -1000); + BattStatus = Irp->AssociatedIrp.SystemBuffer; Status = BattClass->MiniportInfo.QueryStatus(BattClass->MiniportInfo.Context, BattWait.BatteryTag, - (PBATTERY_STATUS)Irp->AssociatedIrp.SystemBuffer); - - BattStatus = Irp->AssociatedIrp.SystemBuffer; + BattStatus); if (!NT_SUCCESS(Status) || - ((BattWait.PowerState & BattStatus->PowerState) && - (BattWait.HighCapacity <= BattStatus->Capacity) && - (BattWait.LowCapacity >= BattStatus->Capacity))) + (BattWait.PowerState == BattStatus->PowerState && + BattWait.HighCapacity >= BattStatus->Capacity && + BattWait.LowCapacity <= BattStatus->Capacity)) { BattNotify.PowerState = BattWait.PowerState; BattNotify.HighCapacity = BattWait.HighCapacity; @@ -304,25 +303,14 @@ BatteryClassIoctl(PVOID ClassData, KernelMode, FALSE, BattWait.Timeout != -1 ? &Timeout : NULL); + if (Status == STATUS_TIMEOUT) + Status = STATUS_SUCCESS; ExAcquireFastMutex(&BattClass->Mutex); BattClass->Waiting = FALSE; ExReleaseFastMutex(&BattClass->Mutex); 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 {