https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b0680d65feeed36b931e77f7ef861e8799725bc6

commit b0680d65feeed36b931e77f7ef861e8799725bc6
Author:     George Bișoc <george.bi...@reactos.org>
AuthorDate: Sat Dec 14 13:48:46 2024 +0100
Commit:     George Bișoc <george.bi...@reactos.org>
CommitDate: Tue Dec 17 14:23:33 2024 +0100

    [BATTC] Signal the wait battery tag event when notifying Battery Class
    
    BatteryClassStatusNotify is used by battery miniport drivers to notify the 
Battery Class of a status change. This can either be a battery status change or 
battery tag assignation, depending on what the device extension (namely the 
composite battery) waits for.
    
    We do have implementation for EVENT_BATTERY_STATUS but not for 
EVENT_BATTERY_TAG. What happens is when BatteryClassIoctl fails to query the 
battery tag because it has not yet been assigned, the thread is stuck on 
waiting for the event object to be signaled, forever.
    This tipically happens when a timeout of -1 (meaning the calling thread 
must wait indefinitely) is supplied. The composite battery driver (COMPBATT) is 
responsible to signal the Battery Class when a CM (Control Method) ACPI battery 
receives a tag, which then this function will signal the event.
    
    CORE-18969
    CORE-19452
---
 drivers/battery/battc/battc.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/battery/battc/battc.c b/drivers/battery/battc/battc.c
index 84ae9df061e..e724f720b5f 100644
--- a/drivers/battery/battc/battc.c
+++ b/drivers/battery/battc/battc.c
@@ -76,11 +76,13 @@ BatteryClassQueryWmiDataBlock(PVOID ClassData,
 BCLASSAPI
 NTSTATUS
 NTAPI
-BatteryClassStatusNotify(PVOID ClassData)
+BatteryClassStatusNotify(
+    _In_ PVOID ClassData)
 {
     PBATTERY_CLASS_DATA BattClass;
     PBATTERY_WAIT_STATUS BattWait;
     BATTERY_STATUS BattStatus;
+    ULONG Tag;
     NTSTATUS Status;
 
     DPRINT("Received battery status notification from %p\n", ClassData);
@@ -99,7 +101,14 @@ BatteryClassStatusNotify(PVOID ClassData)
     {
         case EVENT_BATTERY_TAG:
             ExReleaseFastMutex(&BattClass->Mutex);
-            DPRINT1("Waiting for battery is UNIMPLEMENTED!\n");
+            Status = 
BattClass->MiniportInfo.QueryTag(BattClass->MiniportInfo.Context,
+                                                      &Tag);
+            if (!NT_SUCCESS(Status))
+                return Status;
+
+            ExAcquireFastMutex(&BattClass->Mutex);
+            KeSetEvent(&BattClass->WaitEvent, IO_NO_INCREMENT, FALSE);
+            ExReleaseFastMutex(&BattClass->Mutex);
             break;
 
         case EVENT_BATTERY_STATUS:

Reply via email to