1/*******************************************************************************
2 *
3 * Module Name: utdelete - object deletion and reference count utilities
4 *
5 ******************************************************************************/
6
7/******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2012, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************/
115
116#define __UTDELETE_C__
117
118#include "acpi.h"
119#include "accommon.h"
120#include "acinterp.h"
121#include "acnamesp.h"
122#include "acevents.h"
123
124
125#define _COMPONENT          ACPI_UTILITIES
126        ACPI_MODULE_NAME    ("utdelete")
127
128/* Local prototypes */
129
130static void
131AcpiUtDeleteInternalObj (
132    ACPI_OPERAND_OBJECT     *Object);
133
134static void
135AcpiUtUpdateRefCount (
136    ACPI_OPERAND_OBJECT     *Object,
137    UINT32                  Action);
138
139
140/*******************************************************************************
141 *
142 * FUNCTION:    AcpiUtDeleteInternalObj
143 *
144 * PARAMETERS:  Object         - Object to be deleted
145 *
146 * RETURN:      None
147 *
148 * DESCRIPTION: Low level object deletion, after reference counts have been
149 *              updated (All reference counts, including sub-objects!)
150 *
151 ******************************************************************************/
152
153static void
154AcpiUtDeleteInternalObj (
155    ACPI_OPERAND_OBJECT     *Object)
156{
157    void                    *ObjPointer = NULL;
158    ACPI_OPERAND_OBJECT     *HandlerDesc;
159    ACPI_OPERAND_OBJECT     *SecondDesc;
160    ACPI_OPERAND_OBJECT     *NextDesc;
161    ACPI_OPERAND_OBJECT     **LastObjPtr;
162
163
164    ACPI_FUNCTION_TRACE_PTR (UtDeleteInternalObj, Object);
165
166
167    if (!Object)
168    {
169        return_VOID;
170    }
171
172    /*
173     * Must delete or free any pointers within the object that are not
174     * actual ACPI objects (for example, a raw buffer pointer).
175     */
176    switch (Object->Common.Type)
177    {
178    case ACPI_TYPE_STRING:
179
180        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n",
181            Object, Object->String.Pointer));
182
183        /* Free the actual string buffer */
184
185        if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
186        {
187            /* But only if it is NOT a pointer into an ACPI table */
188
189            ObjPointer = Object->String.Pointer;
190        }
191        break;
192
193
194    case ACPI_TYPE_BUFFER:
195
196        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n",
197            Object, Object->Buffer.Pointer));
198
199        /* Free the actual buffer */
200
201        if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
202        {
203            /* But only if it is NOT a pointer into an ACPI table */
204
205            ObjPointer = Object->Buffer.Pointer;
206        }
207        break;
208
209
210    case ACPI_TYPE_PACKAGE:
211
212        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n",
213            Object->Package.Count));
214
215        /*
216         * Elements of the package are not handled here, they are deleted
217         * separately
218         */
219
220        /* Free the (variable length) element pointer array */
221
222        ObjPointer = Object->Package.Elements;
223        break;
224
225
226    /*
227     * These objects have a possible list of notify handlers.
228     * Device object also may have a GPE block.
229     */
230    case ACPI_TYPE_DEVICE:
231
232        if (Object->Device.GpeBlock)
233        {
234            (void) AcpiEvDeleteGpeBlock (Object->Device.GpeBlock);
235        }
236
237        /*lint -fallthrough */
238
239    case ACPI_TYPE_PROCESSOR:
240    case ACPI_TYPE_THERMAL:
241
242        /* Walk the address handler list for this object */
243
244        HandlerDesc = Object->CommonNotify.Handler;
245        while (HandlerDesc)
246        {
247            NextDesc = HandlerDesc->AddressSpace.Next;
248            AcpiUtRemoveReference (HandlerDesc);
249            HandlerDesc = NextDesc;
250        }
251        break;
252
253
254    case ACPI_TYPE_MUTEX:
255
256        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
257            "***** Mutex %p, OS Mutex %p\n",
258            Object, Object->Mutex.OsMutex));
259
260        if (Object == AcpiGbl_GlobalLockMutex)
261        {
262            /* Global Lock has extra semaphore */
263
264            (void) AcpiOsDeleteSemaphore (AcpiGbl_GlobalLockSemaphore);
265            AcpiGbl_GlobalLockSemaphore = NULL;
266
267            AcpiOsDeleteMutex (Object->Mutex.OsMutex);
268            AcpiGbl_GlobalLockMutex = NULL;
269        }
270        else
271        {
272            AcpiExUnlinkMutex (Object);
273            AcpiOsDeleteMutex (Object->Mutex.OsMutex);
274        }
275        break;
276
277
278    case ACPI_TYPE_EVENT:
279
280        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
281            "***** Event %p, OS Semaphore %p\n",
282            Object, Object->Event.OsSemaphore));
283
284        (void) AcpiOsDeleteSemaphore (Object->Event.OsSemaphore);
285        Object->Event.OsSemaphore = NULL;
286        break;
287
288
289    case ACPI_TYPE_METHOD:
290
291        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
292            "***** Method %p\n", Object));
293
294        /* Delete the method mutex if it exists */
295
296        if (Object->Method.Mutex)
297        {
298            AcpiOsDeleteMutex (Object->Method.Mutex->Mutex.OsMutex);
299            AcpiUtDeleteObjectDesc (Object->Method.Mutex);
300            Object->Method.Mutex = NULL;
301        }
302        break;
303
304
305    case ACPI_TYPE_REGION:
306
307        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
308            "***** Region %p\n", Object));
309
310        /*
311         * Update AddressRange list. However, only permanent regions
312         * are installed in this list. (Not created within a method)
313         */
314        if (!(Object->Region.Node->Flags & ANOBJ_TEMPORARY))
315        {
316            AcpiUtRemoveAddressRange (Object->Region.SpaceId,
317                Object->Region.Node);
318        }
319
320        SecondDesc = AcpiNsGetSecondaryObject (Object);
321        if (SecondDesc)
322        {
323            /*
324             * Free the RegionContext if and only if the handler is one of the
325             * default handlers -- and therefore, we created the context object
326             * locally, it was not created by an external caller.
327             */
328            HandlerDesc = Object->Region.Handler;
329            if (HandlerDesc)
330            {
331                NextDesc = HandlerDesc->AddressSpace.RegionList;
332                LastObjPtr = &HandlerDesc->AddressSpace.RegionList;
333
334                /* Remove the region object from the handler's list */
335
336                while (NextDesc)
337                {
338                    if (NextDesc == Object)
339                    {
340                        *LastObjPtr = NextDesc->Region.Next;
341                        break;
342                    }
343
344                    /* Walk the linked list of handler */
345
346                    LastObjPtr = &NextDesc->Region.Next;
347                    NextDesc = NextDesc->Region.Next;
348                }
349
350                if (HandlerDesc->AddressSpace.HandlerFlags &
351                    ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
352                {
353                    /* Deactivate region and free region context */
354
355                    if (HandlerDesc->AddressSpace.Setup)
356                    {
357                        (void) HandlerDesc->AddressSpace.Setup (Object,
358                            ACPI_REGION_DEACTIVATE,
359                            HandlerDesc->AddressSpace.Context,
360                            &SecondDesc->Extra.RegionContext);
361                    }
362                }
363
364                AcpiUtRemoveReference (HandlerDesc);
365            }
366
367            /* Now we can free the Extra object */
368
369            AcpiUtDeleteObjectDesc (SecondDesc);
370        }
371        break;
372
373
374    case ACPI_TYPE_BUFFER_FIELD:
375
376        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
377            "***** Buffer Field %p\n", Object));
378
379        SecondDesc = AcpiNsGetSecondaryObject (Object);
380        if (SecondDesc)
381        {
382            AcpiUtDeleteObjectDesc (SecondDesc);
383        }
384        break;
385
386
387    case ACPI_TYPE_LOCAL_BANK_FIELD:
388
389        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
390            "***** Bank Field %p\n", Object));
391
392        SecondDesc = AcpiNsGetSecondaryObject (Object);
393        if (SecondDesc)
394        {
395            AcpiUtDeleteObjectDesc (SecondDesc);
396        }
397        break;
398
399
400    default:
401        break;
402    }
403
404    /* Free any allocated memory (pointer within the object) found above */
405
406    if (ObjPointer)
407    {
408        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n",
409            ObjPointer));
410        ACPI_FREE (ObjPointer);
411    }
412
413    /* Now the object can be safely deleted */
414
415    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object %p [%s]\n",
416        Object, AcpiUtGetObjectTypeName (Object)));
417
418    AcpiUtDeleteObjectDesc (Object);
419    return_VOID;
420}
421
422
423/*******************************************************************************
424 *
425 * FUNCTION:    AcpiUtDeleteInternalObjectList
426 *
427 * PARAMETERS:  ObjList         - Pointer to the list to be deleted
428 *
429 * RETURN:      None
430 *
431 * DESCRIPTION: This function deletes an internal object list, including both
432 *              simple objects and package objects
433 *
434 ******************************************************************************/
435
436void
437AcpiUtDeleteInternalObjectList (
438    ACPI_OPERAND_OBJECT     **ObjList)
439{
440    ACPI_OPERAND_OBJECT     **InternalObj;
441
442
443    ACPI_FUNCTION_TRACE (UtDeleteInternalObjectList);
444
445
446    /* Walk the null-terminated internal list */
447
448    for (InternalObj = ObjList; *InternalObj; InternalObj++)
449    {
450        AcpiUtRemoveReference (*InternalObj);
451    }
452
453    /* Free the combined parameter pointer list and object array */
454
455    ACPI_FREE (ObjList);
456    return_VOID;
457}
458
459
460/*******************************************************************************
461 *
462 * FUNCTION:    AcpiUtUpdateRefCount
463 *
464 * PARAMETERS:  Object          - Object whose ref count is to be updated
465 *              Action          - What to do
466 *
467 * RETURN:      New ref count
468 *
469 * DESCRIPTION: Modify the ref count and return it.
470 *
471 ******************************************************************************/
472
473static void
474AcpiUtUpdateRefCount (
475    ACPI_OPERAND_OBJECT     *Object,
476    UINT32                  Action)
477{
478    UINT16                  Count;
479    UINT16                  NewCount;
480
481
482    ACPI_FUNCTION_NAME (UtUpdateRefCount);
483
484
485    if (!Object)
486    {
487        return;
488    }
489
490    Count = Object->Common.ReferenceCount;
491    NewCount = Count;
492
493    /*
494     * Perform the reference count action (increment, decrement, force delete)
495     */
496    switch (Action)
497    {
498    case REF_INCREMENT:
499
500        NewCount++;
501        Object->Common.ReferenceCount = NewCount;
502
503        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
504            "Obj %p Refs=%X, [Incremented]\n",
505            Object, NewCount));
506        break;
507
508    case REF_DECREMENT:
509
510        if (Count < 1)
511        {
512            ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
513                "Obj %p Refs=%X, can't decrement! (Set to 0)\n",
514                Object, NewCount));
515
516            NewCount = 0;
517        }
518        else
519        {
520            NewCount--;
521
522            ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
523                "Obj %p Refs=%X, [Decremented]\n",
524                Object, NewCount));
525        }
526
527        if (Object->Common.Type == ACPI_TYPE_METHOD)
528        {
529            ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
530                "Method Obj %p Refs=%X, [Decremented]\n", Object, NewCount));
531        }
532
533        Object->Common.ReferenceCount = NewCount;
534        if (NewCount == 0)
535        {
536            AcpiUtDeleteInternalObj (Object);
537        }
538        break;
539
540    case REF_FORCE_DELETE:
541
542        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
543            "Obj %p Refs=%X, Force delete! (Set to 0)\n", Object, Count));
544
545        NewCount = 0;
546        Object->Common.ReferenceCount = NewCount;
547        AcpiUtDeleteInternalObj (Object);
548        break;
549
550    default:
551
552        ACPI_ERROR ((AE_INFO, "Unknown action (0x%X)", Action));
553        break;
554    }
555
556    /*
557     * Sanity check the reference count, for debug purposes only.
558     * (A deleted object will have a huge reference count)
559     */
560    if (Count > ACPI_MAX_REFERENCE_COUNT)
561    {
562        ACPI_WARNING ((AE_INFO,
563            "Large Reference Count (0x%X) in object %p", Count, Object));
564    }
565}
566
567
568/*******************************************************************************
569 *
570 * FUNCTION:    AcpiUtUpdateObjectReference
571 *
572 * PARAMETERS:  Object              - Increment ref count for this object
573 *                                    and all sub-objects
574 *              Action              - Either REF_INCREMENT or REF_DECREMENT or
575 *                                    REF_FORCE_DELETE
576 *
577 * RETURN:      Status
578 *
579 * DESCRIPTION: Increment the object reference count
580 *
581 * Object references are incremented when:
582 * 1) An object is attached to a Node (namespace object)
583 * 2) An object is copied (all subobjects must be incremented)
584 *
585 * Object references are decremented when:
586 * 1) An object is detached from an Node
587 *
588 ******************************************************************************/
589
590ACPI_STATUS
591AcpiUtUpdateObjectReference (
592    ACPI_OPERAND_OBJECT     *Object,
593    UINT16                  Action)
594{
595    ACPI_STATUS             Status = AE_OK;
596    ACPI_GENERIC_STATE      *StateList = NULL;
597    ACPI_OPERAND_OBJECT     *NextObject = NULL;
598    ACPI_OPERAND_OBJECT     *PrevObject;
599    ACPI_GENERIC_STATE      *State;
600    UINT32                  i;
601
602
603    ACPI_FUNCTION_TRACE_PTR (UtUpdateObjectReference, Object);
604
605
606    while (Object)
607    {
608        /* Make sure that this isn't a namespace handle */
609
610        if (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED)
611        {
612            ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
613                "Object %p is NS handle\n", Object));
614            return_ACPI_STATUS (AE_OK);
615        }
616
617        /*
618         * All sub-objects must have their reference count incremented also.
619         * Different object types have different subobjects.
620         */
621        switch (Object->Common.Type)
622        {
623        case ACPI_TYPE_DEVICE:
624        case ACPI_TYPE_PROCESSOR:
625        case ACPI_TYPE_POWER:
626        case ACPI_TYPE_THERMAL:
627
628            /*
629             * Update the notify objects for these types (if present)
630             * Two lists, system and device notify handlers.
631             */
632            for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
633            {
634                PrevObject = Object->CommonNotify.NotifyList[i];
635                while (PrevObject)
636                {
637                    NextObject = PrevObject->Notify.Next[i];
638                    AcpiUtUpdateRefCount (PrevObject, Action);
639                    PrevObject = NextObject;
640                }
641            }
642            break;
643
644        case ACPI_TYPE_PACKAGE:
645            /*
646             * We must update all the sub-objects of the package,
647             * each of whom may have their own sub-objects.
648             */
649            for (i = 0; i < Object->Package.Count; i++)
650            {
651                /*
652                 * Push each element onto the stack for later processing.
653                 * Note: There can be null elements within the package,
654                 * these are simply ignored
655                 */
656                Status = AcpiUtCreateUpdateStateAndPush (
657                            Object->Package.Elements[i], Action, &StateList);
658                if (ACPI_FAILURE (Status))
659                {
660                    goto ErrorExit;
661                }
662            }
663            break;
664
665        case ACPI_TYPE_BUFFER_FIELD:
666
667            NextObject = Object->BufferField.BufferObj;
668            break;
669
670        case ACPI_TYPE_LOCAL_REGION_FIELD:
671
672            NextObject = Object->Field.RegionObj;
673            break;
674
675        case ACPI_TYPE_LOCAL_BANK_FIELD:
676
677            NextObject = Object->BankField.BankObj;
678            Status = AcpiUtCreateUpdateStateAndPush (
679                        Object->BankField.RegionObj, Action, &StateList);
680            if (ACPI_FAILURE (Status))
681            {
682                goto ErrorExit;
683            }
684            break;
685
686        case ACPI_TYPE_LOCAL_INDEX_FIELD:
687
688            NextObject = Object->IndexField.IndexObj;
689            Status = AcpiUtCreateUpdateStateAndPush (
690                        Object->IndexField.DataObj, Action, &StateList);
691            if (ACPI_FAILURE (Status))
692            {
693                goto ErrorExit;
694            }
695            break;
696
697        case ACPI_TYPE_LOCAL_REFERENCE:
698            /*
699             * The target of an Index (a package, string, or buffer) or a named
700             * reference must track changes to the ref count of the index or
701             * target object.
702             */
703            if ((Object->Reference.Class == ACPI_REFCLASS_INDEX) ||
704                (Object->Reference.Class== ACPI_REFCLASS_NAME))
705            {
706                NextObject = Object->Reference.Object;
707            }
708            break;
709
710        case ACPI_TYPE_REGION:
711        default:
712            break; /* No subobjects for all other types */
713        }
714
715        /*
716         * Now we can update the count in the main object. This can only
717         * happen after we update the sub-objects in case this causes the
718         * main object to be deleted.
719         */
720        AcpiUtUpdateRefCount (Object, Action);
721        Object = NULL;
722
723        /* Move on to the next object to be updated */
724
725        if (NextObject)
726        {
727            Object = NextObject;
728            NextObject = NULL;
729        }
730        else if (StateList)
731        {
732            State = AcpiUtPopGenericState (&StateList);
733            Object = State->Update.Object;
734            AcpiUtDeleteGenericState (State);
735        }
736    }
737
738    return_ACPI_STATUS (AE_OK);
739
740
741ErrorExit:
742
743    ACPI_EXCEPTION ((AE_INFO, Status,
744        "Could not update object reference count"));
745
746    /* Free any stacked Update State objects */
747
748    while (StateList)
749    {
750        State = AcpiUtPopGenericState (&StateList);
751        AcpiUtDeleteGenericState (State);
752    }
753
754    return_ACPI_STATUS (Status);
755}
756
757
758/*******************************************************************************
759 *
760 * FUNCTION:    AcpiUtAddReference
761 *
762 * PARAMETERS:  Object          - Object whose reference count is to be
763 *                                incremented
764 *
765 * RETURN:      None
766 *
767 * DESCRIPTION: Add one reference to an ACPI object
768 *
769 ******************************************************************************/
770
771void
772AcpiUtAddReference (
773    ACPI_OPERAND_OBJECT     *Object)
774{
775
776    ACPI_FUNCTION_TRACE_PTR (UtAddReference, Object);
777
778
779    /* Ensure that we have a valid object */
780
781    if (!AcpiUtValidInternalObject (Object))
782    {
783        return_VOID;
784    }
785
786    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
787        "Obj %p Current Refs=%X [To Be Incremented]\n",
788        Object, Object->Common.ReferenceCount));
789
790    /* Increment the reference count */
791
792    (void) AcpiUtUpdateObjectReference (Object, REF_INCREMENT);
793    return_VOID;
794}
795
796
797/*******************************************************************************
798 *
799 * FUNCTION:    AcpiUtRemoveReference
800 *
801 * PARAMETERS:  Object         - Object whose ref count will be decremented
802 *
803 * RETURN:      None
804 *
805 * DESCRIPTION: Decrement the reference count of an ACPI internal object
806 *
807 ******************************************************************************/
808
809void
810AcpiUtRemoveReference (
811    ACPI_OPERAND_OBJECT     *Object)
812{
813
814    ACPI_FUNCTION_TRACE_PTR (UtRemoveReference, Object);
815
816
817    /*
818     * Allow a NULL pointer to be passed in, just ignore it. This saves
819     * each caller from having to check. Also, ignore NS nodes.
820     *
821     */
822    if (!Object ||
823        (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED))
824
825    {
826        return_VOID;
827    }
828
829    /* Ensure that we have a valid object */
830
831    if (!AcpiUtValidInternalObject (Object))
832    {
833        return_VOID;
834    }
835
836    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
837        "Obj %p Current Refs=%X [To Be Decremented]\n",
838        Object, Object->Common.ReferenceCount));
839
840    /*
841     * Decrement the reference count, and only actually delete the object
842     * if the reference count becomes 0. (Must also decrement the ref count
843     * of all subobjects!)
844     */
845    (void) AcpiUtUpdateObjectReference (Object, REF_DECREMENT);
846    return_VOID;
847}
848