]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOServicePM.cpp
xnu-792.6.22.tar.gz
[apple/xnu.git] / iokit / Kernel / IOServicePM.cpp
index af7e11dd009aca592cb08001c238d21b3aa6813d..a20e0a6a091464505a5b068db938829c413ebb05 100644 (file)
@@ -2264,15 +2264,22 @@ bool IOService::notifyChild ( IOPowerConnection * theNub, bool is_prechange )
 {
     IOReturn                            k = IOPMAckImplied;
     unsigned long                       childPower;
-    IOService                           *theChild = (IOService *)(theNub->copyChildEntry(gIOPowerPlane));
-
-    theNub->setAwaitingAck(true);                                      // in case they don't ack
+    IOService                           *theChild;
     
-    if ( ! theChild ) 
+    theChild = (IOService *)(theNub->copyChildEntry(gIOPowerPlane));
+    if(!theChild) 
     {
+        // The child has been detached since we grabbed the child iterator.
+        // Decrement pending_acks, already incremented in notifyAll,
+        // to account for this unexpected departure.
+        priv->head_note_pendingAcks--;
         return true;
     }
     
+    // Unless the child handles the notification immediately and returns
+    // kIOPMAckImplied, we'll be awaiting their acknowledgement later.
+    theNub->setAwaitingAck(true);
+    
     if ( is_prechange ) 
     {
         k = theChild->powerDomainWillChangeTo(priv->head_note_outputFlags,theNub);
@@ -2284,7 +2291,7 @@ bool IOService::notifyChild ( IOPowerConnection * theNub, bool is_prechange )
     if ( k == IOPMAckImplied ) 
     {
         // yes
-        priv->head_note_pendingAcks -=1;
+        priv->head_note_pendingAcks--;
         theNub->setAwaitingAck(false);
         childPower = theChild->currentPowerConsumption();
         if ( childPower == kIOPMUnknown )