Path: blob/main/sys/contrib/dev/acpica/components/utilities/utdelete.c
48406 views
/*******************************************************************************1*2* Module Name: utdelete - object deletion and reference count utilities3*4******************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acinterp.h>154#include <contrib/dev/acpica/include/acnamesp.h>155#include <contrib/dev/acpica/include/acevents.h>156157158#define _COMPONENT ACPI_UTILITIES159ACPI_MODULE_NAME ("utdelete")160161/* Local prototypes */162163static void164AcpiUtDeleteInternalObj (165ACPI_OPERAND_OBJECT *Object);166167static void168AcpiUtUpdateRefCount (169ACPI_OPERAND_OBJECT *Object,170UINT32 Action);171172173/*******************************************************************************174*175* FUNCTION: AcpiUtDeleteInternalObj176*177* PARAMETERS: Object - Object to be deleted178*179* RETURN: None180*181* DESCRIPTION: Low level object deletion, after reference counts have been182* updated (All reference counts, including sub-objects!)183*184******************************************************************************/185186static void187AcpiUtDeleteInternalObj (188ACPI_OPERAND_OBJECT *Object)189{190void *ObjPointer = NULL;191ACPI_OPERAND_OBJECT *HandlerDesc;192ACPI_OPERAND_OBJECT *SecondDesc;193ACPI_OPERAND_OBJECT *NextDesc;194ACPI_OPERAND_OBJECT *StartDesc;195ACPI_OPERAND_OBJECT **LastObjPtr;196197198ACPI_FUNCTION_TRACE_PTR (UtDeleteInternalObj, Object);199200201if (!Object)202{203return_VOID;204}205206/*207* Must delete or free any pointers within the object that are not208* actual ACPI objects (for example, a raw buffer pointer).209*/210switch (Object->Common.Type)211{212case ACPI_TYPE_STRING:213214ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n",215Object, Object->String.Pointer));216217/* Free the actual string buffer */218219if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))220{221/* But only if it is NOT a pointer into an ACPI table */222223ObjPointer = Object->String.Pointer;224}225break;226227case ACPI_TYPE_BUFFER:228229ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n",230Object, Object->Buffer.Pointer));231232/* Free the actual buffer */233234if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))235{236/* But only if it is NOT a pointer into an ACPI table */237238ObjPointer = Object->Buffer.Pointer;239}240break;241242case ACPI_TYPE_PACKAGE:243244ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n",245Object->Package.Count));246247/*248* Elements of the package are not handled here, they are deleted249* separately250*/251252/* Free the (variable length) element pointer array */253254ObjPointer = Object->Package.Elements;255break;256257/*258* These objects have a possible list of notify handlers.259* Device object also may have a GPE block.260*/261case ACPI_TYPE_DEVICE:262263if (Object->Device.GpeBlock)264{265(void) AcpiEvDeleteGpeBlock (Object->Device.GpeBlock);266}267268ACPI_FALLTHROUGH;269270case ACPI_TYPE_PROCESSOR:271case ACPI_TYPE_THERMAL:272273/* Walk the address handler list for this object */274275HandlerDesc = Object->CommonNotify.Handler;276while (HandlerDesc)277{278NextDesc = HandlerDesc->AddressSpace.Next;279AcpiUtRemoveReference (HandlerDesc);280HandlerDesc = NextDesc;281}282break;283284case ACPI_TYPE_MUTEX:285286ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,287"***** Mutex %p, OS Mutex %p\n",288Object, Object->Mutex.OsMutex));289290if (Object == AcpiGbl_GlobalLockMutex)291{292/* Global Lock has extra semaphore */293294(void) AcpiOsDeleteSemaphore (AcpiGbl_GlobalLockSemaphore);295AcpiGbl_GlobalLockSemaphore = ACPI_SEMAPHORE_NULL;296297AcpiOsDeleteMutex (Object->Mutex.OsMutex);298AcpiGbl_GlobalLockMutex = NULL;299}300else301{302AcpiExUnlinkMutex (Object);303AcpiOsDeleteMutex (Object->Mutex.OsMutex);304}305break;306307case ACPI_TYPE_EVENT:308309ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,310"***** Event %p, OS Semaphore %p\n",311Object, Object->Event.OsSemaphore));312313(void) AcpiOsDeleteSemaphore (Object->Event.OsSemaphore);314Object->Event.OsSemaphore = ACPI_SEMAPHORE_NULL;315break;316317case ACPI_TYPE_METHOD:318319ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,320"***** Method %p\n", Object));321322/* Delete the method mutex if it exists */323324if (Object->Method.Mutex)325{326AcpiOsDeleteMutex (Object->Method.Mutex->Mutex.OsMutex);327AcpiUtDeleteObjectDesc (Object->Method.Mutex);328Object->Method.Mutex = NULL;329}330331if (Object->Method.Node)332{333Object->Method.Node = NULL;334}335break;336337case ACPI_TYPE_REGION:338339ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,340"***** Region %p\n", Object));341342/*343* Update AddressRange list. However, only permanent regions344* are installed in this list. (Not created within a method)345*/346if (!(Object->Region.Node->Flags & ANOBJ_TEMPORARY))347{348AcpiUtRemoveAddressRange (Object->Region.SpaceId,349Object->Region.Node);350}351352SecondDesc = AcpiNsGetSecondaryObject (Object);353if (SecondDesc)354{355/*356* Free the RegionContext if and only if the handler is one of the357* default handlers -- and therefore, we created the context object358* locally, it was not created by an external caller.359*/360HandlerDesc = Object->Region.Handler;361if (HandlerDesc)362{363NextDesc = HandlerDesc->AddressSpace.RegionList;364StartDesc = NextDesc;365LastObjPtr = &HandlerDesc->AddressSpace.RegionList;366367/* Remove the region object from the handler list */368369while (NextDesc)370{371if (NextDesc == Object)372{373*LastObjPtr = NextDesc->Region.Next;374break;375}376377/* Walk the linked list of handlers */378379LastObjPtr = &NextDesc->Region.Next;380NextDesc = NextDesc->Region.Next;381382/* Prevent infinite loop if list is corrupted */383384if (NextDesc == StartDesc)385{386ACPI_ERROR ((AE_INFO,387"Circular region list in address handler object %p",388HandlerDesc));389return_VOID;390}391}392393if (HandlerDesc->AddressSpace.HandlerFlags &394ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)395{396/* Deactivate region and free region context */397398if (HandlerDesc->AddressSpace.Setup)399{400(void) HandlerDesc->AddressSpace.Setup (Object,401ACPI_REGION_DEACTIVATE,402HandlerDesc->AddressSpace.Context,403&SecondDesc->Extra.RegionContext);404}405}406407AcpiUtRemoveReference (HandlerDesc);408}409410/* Now we can free the Extra object */411412AcpiUtDeleteObjectDesc (SecondDesc);413}414if (Object->Field.InternalPccBuffer)415{416ACPI_FREE(Object->Field.InternalPccBuffer);417}418419break;420421case ACPI_TYPE_BUFFER_FIELD:422423ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,424"***** Buffer Field %p\n", Object));425426SecondDesc = AcpiNsGetSecondaryObject (Object);427if (SecondDesc)428{429AcpiUtDeleteObjectDesc (SecondDesc);430}431break;432433case ACPI_TYPE_LOCAL_BANK_FIELD:434435ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,436"***** Bank Field %p\n", Object));437438SecondDesc = AcpiNsGetSecondaryObject (Object);439if (SecondDesc)440{441AcpiUtDeleteObjectDesc (SecondDesc);442}443break;444445case ACPI_TYPE_LOCAL_ADDRESS_HANDLER:446447ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,448"***** Address handler %p\n", Object));449450AcpiOsDeleteMutex (Object->AddressSpace.ContextMutex);451break;452453default:454455break;456}457458/* Free any allocated memory (pointer within the object) found above */459460if (ObjPointer)461{462ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n",463ObjPointer));464ACPI_FREE (ObjPointer);465}466467/* Now the object can be safely deleted */468469ACPI_DEBUG_PRINT_RAW ((ACPI_DB_ALLOCATIONS, "%s: Deleting Object %p [%s]\n",470ACPI_GET_FUNCTION_NAME, Object, AcpiUtGetObjectTypeName (Object)));471472AcpiUtDeleteObjectDesc (Object);473return_VOID;474}475476477/*******************************************************************************478*479* FUNCTION: AcpiUtDeleteInternalObjectList480*481* PARAMETERS: ObjList - Pointer to the list to be deleted482*483* RETURN: None484*485* DESCRIPTION: This function deletes an internal object list, including both486* simple objects and package objects487*488******************************************************************************/489490void491AcpiUtDeleteInternalObjectList (492ACPI_OPERAND_OBJECT **ObjList)493{494ACPI_OPERAND_OBJECT **InternalObj;495496497ACPI_FUNCTION_ENTRY ();498499500/* Walk the null-terminated internal list */501502for (InternalObj = ObjList; *InternalObj; InternalObj++)503{504AcpiUtRemoveReference (*InternalObj);505}506507/* Free the combined parameter pointer list and object array */508509ACPI_FREE (ObjList);510return;511}512513514/*******************************************************************************515*516* FUNCTION: AcpiUtUpdateRefCount517*518* PARAMETERS: Object - Object whose ref count is to be updated519* Action - What to do (REF_INCREMENT or REF_DECREMENT)520*521* RETURN: None. Sets new reference count within the object522*523* DESCRIPTION: Modify the reference count for an internal acpi object524*525******************************************************************************/526527static void528AcpiUtUpdateRefCount (529ACPI_OPERAND_OBJECT *Object,530UINT32 Action)531{532UINT16 OriginalCount;533UINT16 NewCount = 0;534ACPI_CPU_FLAGS LockFlags;535char *Message;536537538ACPI_FUNCTION_NAME (UtUpdateRefCount);539540541if (!Object)542{543return;544}545546/*547* Always get the reference count lock. Note: Interpreter and/or548* Namespace is not always locked when this function is called.549*/550LockFlags = AcpiOsAcquireLock (AcpiGbl_ReferenceCountLock);551OriginalCount = Object->Common.ReferenceCount;552553/* Perform the reference count action (increment, decrement) */554555switch (Action)556{557case REF_INCREMENT:558559NewCount = OriginalCount + 1;560Object->Common.ReferenceCount = NewCount;561AcpiOsReleaseLock (AcpiGbl_ReferenceCountLock, LockFlags);562563/* The current reference count should never be zero here */564565if (!OriginalCount)566{567ACPI_WARNING ((AE_INFO,568"Obj %p, Reference Count was zero before increment\n",569Object));570}571572ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,573"Obj %p Type %.2X [%s] Refs %.2X [Incremented]\n",574Object, Object->Common.Type,575AcpiUtGetObjectTypeName (Object), NewCount));576Message = "Increment";577break;578579case REF_DECREMENT:580581/* The current reference count must be non-zero */582583if (OriginalCount)584{585NewCount = OriginalCount - 1;586Object->Common.ReferenceCount = NewCount;587}588589AcpiOsReleaseLock (AcpiGbl_ReferenceCountLock, LockFlags);590591if (!OriginalCount)592{593ACPI_WARNING ((AE_INFO,594"Obj %p, Reference Count is already zero, cannot decrement\n",595Object));596return;597}598599ACPI_DEBUG_PRINT_RAW ((ACPI_DB_ALLOCATIONS,600"%s: Obj %p Type %.2X Refs %.2X [Decremented]\n",601ACPI_GET_FUNCTION_NAME, Object, Object->Common.Type, NewCount));602603/* Actually delete the object on a reference count of zero */604605if (NewCount == 0)606{607AcpiUtDeleteInternalObj (Object);608}609Message = "Decrement";610break;611612default:613614AcpiOsReleaseLock (AcpiGbl_ReferenceCountLock, LockFlags);615ACPI_ERROR ((AE_INFO, "Unknown Reference Count action (0x%X)",616Action));617return;618}619620/*621* Sanity check the reference count, for debug purposes only.622* (A deleted object will have a huge reference count)623*/624if (NewCount > ACPI_MAX_REFERENCE_COUNT)625{626ACPI_WARNING ((AE_INFO,627"Large Reference Count (0x%X) in object %p, Type=0x%.2X Operation=%s",628NewCount, Object, Object->Common.Type, Message));629}630}631632633/*******************************************************************************634*635* FUNCTION: AcpiUtUpdateObjectReference636*637* PARAMETERS: Object - Increment or decrement the ref count for638* this object and all sub-objects639* Action - Either REF_INCREMENT or REF_DECREMENT640*641* RETURN: Status642*643* DESCRIPTION: Increment or decrement the object reference count644*645* Object references are incremented when:646* 1) An object is attached to a Node (namespace object)647* 2) An object is copied (all subobjects must be incremented)648*649* Object references are decremented when:650* 1) An object is detached from an Node651*652******************************************************************************/653654ACPI_STATUS655AcpiUtUpdateObjectReference (656ACPI_OPERAND_OBJECT *Object,657UINT16 Action)658{659ACPI_STATUS Status = AE_OK;660ACPI_GENERIC_STATE *StateList = NULL;661ACPI_OPERAND_OBJECT *NextObject = NULL;662ACPI_OPERAND_OBJECT *PrevObject;663ACPI_GENERIC_STATE *State;664UINT32 i;665666667ACPI_FUNCTION_NAME (UtUpdateObjectReference);668669670while (Object)671{672/* Make sure that this isn't a namespace handle */673674if (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED)675{676ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,677"Object %p is NS handle\n", Object));678return (AE_OK);679}680681/*682* All sub-objects must have their reference count updated683* also. Different object types have different subobjects.684*/685switch (Object->Common.Type)686{687case ACPI_TYPE_DEVICE:688case ACPI_TYPE_PROCESSOR:689case ACPI_TYPE_POWER:690case ACPI_TYPE_THERMAL:691/*692* Update the notify objects for these types (if present)693* Two lists, system and device notify handlers.694*/695for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)696{697PrevObject = Object->CommonNotify.NotifyList[i];698while (PrevObject)699{700NextObject = PrevObject->Notify.Next[i];701AcpiUtUpdateRefCount (PrevObject, Action);702PrevObject = NextObject;703}704}705break;706707case ACPI_TYPE_PACKAGE:708/*709* We must update all the sub-objects of the package,710* each of whom may have their own sub-objects.711*/712for (i = 0; i < Object->Package.Count; i++)713{714/*715* Null package elements are legal and can be simply716* ignored.717*/718NextObject = Object->Package.Elements[i];719if (!NextObject)720{721continue;722}723724switch (NextObject->Common.Type)725{726case ACPI_TYPE_INTEGER:727case ACPI_TYPE_STRING:728case ACPI_TYPE_BUFFER:729/*730* For these very simple sub-objects, we can just731* update the reference count here and continue.732* Greatly increases performance of this operation.733*/734AcpiUtUpdateRefCount (NextObject, Action);735break;736737default:738/*739* For complex sub-objects, push them onto the stack740* for later processing (this eliminates recursion.)741*/742Status = AcpiUtCreateUpdateStateAndPush (743NextObject, Action, &StateList);744if (ACPI_FAILURE (Status))745{746goto ErrorExit;747}748break;749}750}751752NextObject = NULL;753break;754755case ACPI_TYPE_BUFFER_FIELD:756757NextObject = Object->BufferField.BufferObj;758break;759760case ACPI_TYPE_LOCAL_BANK_FIELD:761762NextObject = Object->BankField.BankObj;763Status = AcpiUtCreateUpdateStateAndPush (764Object->BankField.RegionObj, Action, &StateList);765if (ACPI_FAILURE (Status))766{767goto ErrorExit;768}769break;770771case ACPI_TYPE_LOCAL_INDEX_FIELD:772773NextObject = Object->IndexField.IndexObj;774Status = AcpiUtCreateUpdateStateAndPush (775Object->IndexField.DataObj, Action, &StateList);776if (ACPI_FAILURE (Status))777{778goto ErrorExit;779}780break;781782case ACPI_TYPE_LOCAL_REFERENCE:783/*784* The target of an Index (a package, string, or buffer) or a named785* reference must track changes to the ref count of the index or786* target object.787*/788if ((Object->Reference.Class == ACPI_REFCLASS_INDEX) ||789(Object->Reference.Class== ACPI_REFCLASS_NAME))790{791NextObject = Object->Reference.Object;792}793break;794795case ACPI_TYPE_LOCAL_REGION_FIELD:796case ACPI_TYPE_REGION:797default:798799break; /* No subobjects for all other types */800}801802/*803* Now we can update the count in the main object. This can only804* happen after we update the sub-objects in case this causes the805* main object to be deleted.806*/807AcpiUtUpdateRefCount (Object, Action);808Object = NULL;809810/* Move on to the next object to be updated */811812if (NextObject)813{814Object = NextObject;815NextObject = NULL;816}817else if (StateList)818{819State = AcpiUtPopGenericState (&StateList);820Object = State->Update.Object;821AcpiUtDeleteGenericState (State);822}823}824825return (AE_OK);826827828ErrorExit:829830ACPI_EXCEPTION ((AE_INFO, Status,831"Could not update object reference count"));832833/* Free any stacked Update State objects */834835while (StateList)836{837State = AcpiUtPopGenericState (&StateList);838AcpiUtDeleteGenericState (State);839}840841return (Status);842}843844845/*******************************************************************************846*847* FUNCTION: AcpiUtAddReference848*849* PARAMETERS: Object - Object whose reference count is to be850* incremented851*852* RETURN: None853*854* DESCRIPTION: Add one reference to an ACPI object855*856******************************************************************************/857858void859AcpiUtAddReference (860ACPI_OPERAND_OBJECT *Object)861{862863ACPI_FUNCTION_NAME (UtAddReference);864865866/* Ensure that we have a valid object */867868if (!AcpiUtValidInternalObject (Object))869{870return;871}872873ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,874"Obj %p Current Refs=%X [To Be Incremented]\n",875Object, Object->Common.ReferenceCount));876877/* Increment the reference count */878879(void) AcpiUtUpdateObjectReference (Object, REF_INCREMENT);880return;881}882883884/*******************************************************************************885*886* FUNCTION: AcpiUtRemoveReference887*888* PARAMETERS: Object - Object whose ref count will be decremented889*890* RETURN: None891*892* DESCRIPTION: Decrement the reference count of an ACPI internal object893*894******************************************************************************/895896void897AcpiUtRemoveReference (898ACPI_OPERAND_OBJECT *Object)899{900901ACPI_FUNCTION_NAME (UtRemoveReference);902903904/*905* Allow a NULL pointer to be passed in, just ignore it. This saves906* each caller from having to check. Also, ignore NS nodes.907*/908if (!Object ||909(ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED))910911{912return;913}914915/* Ensure that we have a valid object */916917if (!AcpiUtValidInternalObject (Object))918{919return;920}921922ACPI_DEBUG_PRINT_RAW ((ACPI_DB_ALLOCATIONS,923"%s: Obj %p Current Refs=%X [To Be Decremented]\n",924ACPI_GET_FUNCTION_NAME, Object, Object->Common.ReferenceCount));925926/*927* Decrement the reference count, and only actually delete the object928* if the reference count becomes 0. (Must also decrement the ref count929* of all subobjects!)930*/931(void) AcpiUtUpdateObjectReference (Object, REF_DECREMENT);932return;933}934935936