utdelete.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*******************************************************************************
  2. *
  3. * Module Name: utdelete - object deletion and reference count utilities
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2014, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acinterp.h"
  45. #include "acnamesp.h"
  46. #include "acevents.h"
  47. #define _COMPONENT ACPI_UTILITIES
  48. ACPI_MODULE_NAME("utdelete")
  49. /* Local prototypes */
  50. static void acpi_ut_delete_internal_obj(union acpi_operand_object *object);
  51. static void
  52. acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action);
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_ut_delete_internal_obj
  56. *
  57. * PARAMETERS: object - Object to be deleted
  58. *
  59. * RETURN: None
  60. *
  61. * DESCRIPTION: Low level object deletion, after reference counts have been
  62. * updated (All reference counts, including sub-objects!)
  63. *
  64. ******************************************************************************/
  65. static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
  66. {
  67. void *obj_pointer = NULL;
  68. union acpi_operand_object *handler_desc;
  69. union acpi_operand_object *second_desc;
  70. union acpi_operand_object *next_desc;
  71. union acpi_operand_object *start_desc;
  72. union acpi_operand_object **last_obj_ptr;
  73. ACPI_FUNCTION_TRACE_PTR(ut_delete_internal_obj, object);
  74. if (!object) {
  75. return_VOID;
  76. }
  77. /*
  78. * Must delete or free any pointers within the object that are not
  79. * actual ACPI objects (for example, a raw buffer pointer).
  80. */
  81. switch (object->common.type) {
  82. case ACPI_TYPE_STRING:
  83. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  84. "**** String %p, ptr %p\n", object,
  85. object->string.pointer));
  86. /* Free the actual string buffer */
  87. if (!(object->common.flags & AOPOBJ_STATIC_POINTER)) {
  88. /* But only if it is NOT a pointer into an ACPI table */
  89. obj_pointer = object->string.pointer;
  90. }
  91. break;
  92. case ACPI_TYPE_BUFFER:
  93. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  94. "**** Buffer %p, ptr %p\n", object,
  95. object->buffer.pointer));
  96. /* Free the actual buffer */
  97. if (!(object->common.flags & AOPOBJ_STATIC_POINTER)) {
  98. /* But only if it is NOT a pointer into an ACPI table */
  99. obj_pointer = object->buffer.pointer;
  100. }
  101. break;
  102. case ACPI_TYPE_PACKAGE:
  103. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  104. " **** Package of count %X\n",
  105. object->package.count));
  106. /*
  107. * Elements of the package are not handled here, they are deleted
  108. * separately
  109. */
  110. /* Free the (variable length) element pointer array */
  111. obj_pointer = object->package.elements;
  112. break;
  113. /*
  114. * These objects have a possible list of notify handlers.
  115. * Device object also may have a GPE block.
  116. */
  117. case ACPI_TYPE_DEVICE:
  118. if (object->device.gpe_block) {
  119. (void)acpi_ev_delete_gpe_block(object->device.
  120. gpe_block);
  121. }
  122. /*lint -fallthrough */
  123. case ACPI_TYPE_PROCESSOR:
  124. case ACPI_TYPE_THERMAL:
  125. /* Walk the address handler list for this object */
  126. handler_desc = object->common_notify.handler;
  127. while (handler_desc) {
  128. next_desc = handler_desc->address_space.next;
  129. acpi_ut_remove_reference(handler_desc);
  130. handler_desc = next_desc;
  131. }
  132. break;
  133. case ACPI_TYPE_MUTEX:
  134. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  135. "***** Mutex %p, OS Mutex %p\n",
  136. object, object->mutex.os_mutex));
  137. if (object == acpi_gbl_global_lock_mutex) {
  138. /* Global Lock has extra semaphore */
  139. (void)
  140. acpi_os_delete_semaphore
  141. (acpi_gbl_global_lock_semaphore);
  142. acpi_gbl_global_lock_semaphore = NULL;
  143. acpi_os_delete_mutex(object->mutex.os_mutex);
  144. acpi_gbl_global_lock_mutex = NULL;
  145. } else {
  146. acpi_ex_unlink_mutex(object);
  147. acpi_os_delete_mutex(object->mutex.os_mutex);
  148. }
  149. break;
  150. case ACPI_TYPE_EVENT:
  151. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  152. "***** Event %p, OS Semaphore %p\n",
  153. object, object->event.os_semaphore));
  154. (void)acpi_os_delete_semaphore(object->event.os_semaphore);
  155. object->event.os_semaphore = NULL;
  156. break;
  157. case ACPI_TYPE_METHOD:
  158. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  159. "***** Method %p\n", object));
  160. /* Delete the method mutex if it exists */
  161. if (object->method.mutex) {
  162. acpi_os_delete_mutex(object->method.mutex->mutex.
  163. os_mutex);
  164. acpi_ut_delete_object_desc(object->method.mutex);
  165. object->method.mutex = NULL;
  166. }
  167. break;
  168. case ACPI_TYPE_REGION:
  169. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  170. "***** Region %p\n", object));
  171. /*
  172. * Update address_range list. However, only permanent regions
  173. * are installed in this list. (Not created within a method)
  174. */
  175. if (!(object->region.node->flags & ANOBJ_TEMPORARY)) {
  176. acpi_ut_remove_address_range(object->region.space_id,
  177. object->region.node);
  178. }
  179. second_desc = acpi_ns_get_secondary_object(object);
  180. if (second_desc) {
  181. /*
  182. * Free the region_context if and only if the handler is one of the
  183. * default handlers -- and therefore, we created the context object
  184. * locally, it was not created by an external caller.
  185. */
  186. handler_desc = object->region.handler;
  187. if (handler_desc) {
  188. next_desc =
  189. handler_desc->address_space.region_list;
  190. start_desc = next_desc;
  191. last_obj_ptr =
  192. &handler_desc->address_space.region_list;
  193. /* Remove the region object from the handler list */
  194. while (next_desc) {
  195. if (next_desc == object) {
  196. *last_obj_ptr =
  197. next_desc->region.next;
  198. break;
  199. }
  200. /* Walk the linked list of handlers */
  201. last_obj_ptr = &next_desc->region.next;
  202. next_desc = next_desc->region.next;
  203. /* Prevent infinite loop if list is corrupted */
  204. if (next_desc == start_desc) {
  205. ACPI_ERROR((AE_INFO,
  206. "Circular region list in address handler object %p",
  207. handler_desc));
  208. return_VOID;
  209. }
  210. }
  211. if (handler_desc->address_space.handler_flags &
  212. ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) {
  213. /* Deactivate region and free region context */
  214. if (handler_desc->address_space.setup) {
  215. (void)handler_desc->
  216. address_space.setup(object,
  217. ACPI_REGION_DEACTIVATE,
  218. handler_desc->
  219. address_space.
  220. context,
  221. &second_desc->
  222. extra.
  223. region_context);
  224. }
  225. }
  226. acpi_ut_remove_reference(handler_desc);
  227. }
  228. /* Now we can free the Extra object */
  229. acpi_ut_delete_object_desc(second_desc);
  230. }
  231. break;
  232. case ACPI_TYPE_BUFFER_FIELD:
  233. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  234. "***** Buffer Field %p\n", object));
  235. second_desc = acpi_ns_get_secondary_object(object);
  236. if (second_desc) {
  237. acpi_ut_delete_object_desc(second_desc);
  238. }
  239. break;
  240. case ACPI_TYPE_LOCAL_BANK_FIELD:
  241. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  242. "***** Bank Field %p\n", object));
  243. second_desc = acpi_ns_get_secondary_object(object);
  244. if (second_desc) {
  245. acpi_ut_delete_object_desc(second_desc);
  246. }
  247. break;
  248. default:
  249. break;
  250. }
  251. /* Free any allocated memory (pointer within the object) found above */
  252. if (obj_pointer) {
  253. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  254. "Deleting Object Subptr %p\n", obj_pointer));
  255. ACPI_FREE(obj_pointer);
  256. }
  257. /* Now the object can be safely deleted */
  258. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Deleting Object %p [%s]\n",
  259. object, acpi_ut_get_object_type_name(object)));
  260. acpi_ut_delete_object_desc(object);
  261. return_VOID;
  262. }
  263. /*******************************************************************************
  264. *
  265. * FUNCTION: acpi_ut_delete_internal_object_list
  266. *
  267. * PARAMETERS: obj_list - Pointer to the list to be deleted
  268. *
  269. * RETURN: None
  270. *
  271. * DESCRIPTION: This function deletes an internal object list, including both
  272. * simple objects and package objects
  273. *
  274. ******************************************************************************/
  275. void acpi_ut_delete_internal_object_list(union acpi_operand_object **obj_list)
  276. {
  277. union acpi_operand_object **internal_obj;
  278. ACPI_FUNCTION_ENTRY();
  279. /* Walk the null-terminated internal list */
  280. for (internal_obj = obj_list; *internal_obj; internal_obj++) {
  281. acpi_ut_remove_reference(*internal_obj);
  282. }
  283. /* Free the combined parameter pointer list and object array */
  284. ACPI_FREE(obj_list);
  285. return;
  286. }
  287. /*******************************************************************************
  288. *
  289. * FUNCTION: acpi_ut_update_ref_count
  290. *
  291. * PARAMETERS: object - Object whose ref count is to be updated
  292. * action - What to do (REF_INCREMENT or REF_DECREMENT)
  293. *
  294. * RETURN: None. Sets new reference count within the object
  295. *
  296. * DESCRIPTION: Modify the reference count for an internal acpi object
  297. *
  298. ******************************************************************************/
  299. static void
  300. acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action)
  301. {
  302. u16 original_count;
  303. u16 new_count = 0;
  304. acpi_cpu_flags lock_flags;
  305. ACPI_FUNCTION_NAME(ut_update_ref_count);
  306. if (!object) {
  307. return;
  308. }
  309. /*
  310. * Always get the reference count lock. Note: Interpreter and/or
  311. * Namespace is not always locked when this function is called.
  312. */
  313. lock_flags = acpi_os_acquire_lock(acpi_gbl_reference_count_lock);
  314. original_count = object->common.reference_count;
  315. /* Perform the reference count action (increment, decrement) */
  316. switch (action) {
  317. case REF_INCREMENT:
  318. new_count = original_count + 1;
  319. object->common.reference_count = new_count;
  320. acpi_os_release_lock(acpi_gbl_reference_count_lock, lock_flags);
  321. /* The current reference count should never be zero here */
  322. if (!original_count) {
  323. ACPI_WARNING((AE_INFO,
  324. "Obj %p, Reference Count was zero before increment\n",
  325. object));
  326. }
  327. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  328. "Obj %p Type %.2X Refs %.2X [Incremented]\n",
  329. object, object->common.type, new_count));
  330. break;
  331. case REF_DECREMENT:
  332. /* The current reference count must be non-zero */
  333. if (original_count) {
  334. new_count = original_count - 1;
  335. object->common.reference_count = new_count;
  336. }
  337. acpi_os_release_lock(acpi_gbl_reference_count_lock, lock_flags);
  338. if (!original_count) {
  339. ACPI_WARNING((AE_INFO,
  340. "Obj %p, Reference Count is already zero, cannot decrement\n",
  341. object));
  342. }
  343. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  344. "Obj %p Type %.2X Refs %.2X [Decremented]\n",
  345. object, object->common.type, new_count));
  346. /* Actually delete the object on a reference count of zero */
  347. if (new_count == 0) {
  348. acpi_ut_delete_internal_obj(object);
  349. }
  350. break;
  351. default:
  352. acpi_os_release_lock(acpi_gbl_reference_count_lock, lock_flags);
  353. ACPI_ERROR((AE_INFO, "Unknown Reference Count action (0x%X)",
  354. action));
  355. return;
  356. }
  357. /*
  358. * Sanity check the reference count, for debug purposes only.
  359. * (A deleted object will have a huge reference count)
  360. */
  361. if (new_count > ACPI_MAX_REFERENCE_COUNT) {
  362. ACPI_WARNING((AE_INFO,
  363. "Large Reference Count (0x%X) in object %p, Type=0x%.2X",
  364. new_count, object, object->common.type));
  365. }
  366. }
  367. /*******************************************************************************
  368. *
  369. * FUNCTION: acpi_ut_update_object_reference
  370. *
  371. * PARAMETERS: object - Increment ref count for this object
  372. * and all sub-objects
  373. * action - Either REF_INCREMENT or REF_DECREMENT
  374. *
  375. * RETURN: Status
  376. *
  377. * DESCRIPTION: Increment the object reference count
  378. *
  379. * Object references are incremented when:
  380. * 1) An object is attached to a Node (namespace object)
  381. * 2) An object is copied (all subobjects must be incremented)
  382. *
  383. * Object references are decremented when:
  384. * 1) An object is detached from an Node
  385. *
  386. ******************************************************************************/
  387. acpi_status
  388. acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
  389. {
  390. acpi_status status = AE_OK;
  391. union acpi_generic_state *state_list = NULL;
  392. union acpi_operand_object *next_object = NULL;
  393. union acpi_operand_object *prev_object;
  394. union acpi_generic_state *state;
  395. u32 i;
  396. ACPI_FUNCTION_NAME(ut_update_object_reference);
  397. while (object) {
  398. /* Make sure that this isn't a namespace handle */
  399. if (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED) {
  400. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  401. "Object %p is NS handle\n", object));
  402. return (AE_OK);
  403. }
  404. /*
  405. * All sub-objects must have their reference count incremented also.
  406. * Different object types have different subobjects.
  407. */
  408. switch (object->common.type) {
  409. case ACPI_TYPE_DEVICE:
  410. case ACPI_TYPE_PROCESSOR:
  411. case ACPI_TYPE_POWER:
  412. case ACPI_TYPE_THERMAL:
  413. /*
  414. * Update the notify objects for these types (if present)
  415. * Two lists, system and device notify handlers.
  416. */
  417. for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
  418. prev_object =
  419. object->common_notify.notify_list[i];
  420. while (prev_object) {
  421. next_object =
  422. prev_object->notify.next[i];
  423. acpi_ut_update_ref_count(prev_object,
  424. action);
  425. prev_object = next_object;
  426. }
  427. }
  428. break;
  429. case ACPI_TYPE_PACKAGE:
  430. /*
  431. * We must update all the sub-objects of the package,
  432. * each of whom may have their own sub-objects.
  433. */
  434. for (i = 0; i < object->package.count; i++) {
  435. /*
  436. * Null package elements are legal and can be simply
  437. * ignored.
  438. */
  439. next_object = object->package.elements[i];
  440. if (!next_object) {
  441. continue;
  442. }
  443. switch (next_object->common.type) {
  444. case ACPI_TYPE_INTEGER:
  445. case ACPI_TYPE_STRING:
  446. case ACPI_TYPE_BUFFER:
  447. /*
  448. * For these very simple sub-objects, we can just
  449. * update the reference count here and continue.
  450. * Greatly increases performance of this operation.
  451. */
  452. acpi_ut_update_ref_count(next_object,
  453. action);
  454. break;
  455. default:
  456. /*
  457. * For complex sub-objects, push them onto the stack
  458. * for later processing (this eliminates recursion.)
  459. */
  460. status =
  461. acpi_ut_create_update_state_and_push
  462. (next_object, action, &state_list);
  463. if (ACPI_FAILURE(status)) {
  464. goto error_exit;
  465. }
  466. break;
  467. }
  468. }
  469. next_object = NULL;
  470. break;
  471. case ACPI_TYPE_BUFFER_FIELD:
  472. next_object = object->buffer_field.buffer_obj;
  473. break;
  474. case ACPI_TYPE_LOCAL_REGION_FIELD:
  475. next_object = object->field.region_obj;
  476. break;
  477. case ACPI_TYPE_LOCAL_BANK_FIELD:
  478. next_object = object->bank_field.bank_obj;
  479. status =
  480. acpi_ut_create_update_state_and_push(object->
  481. bank_field.
  482. region_obj,
  483. action,
  484. &state_list);
  485. if (ACPI_FAILURE(status)) {
  486. goto error_exit;
  487. }
  488. break;
  489. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  490. next_object = object->index_field.index_obj;
  491. status =
  492. acpi_ut_create_update_state_and_push(object->
  493. index_field.
  494. data_obj,
  495. action,
  496. &state_list);
  497. if (ACPI_FAILURE(status)) {
  498. goto error_exit;
  499. }
  500. break;
  501. case ACPI_TYPE_LOCAL_REFERENCE:
  502. /*
  503. * The target of an Index (a package, string, or buffer) or a named
  504. * reference must track changes to the ref count of the index or
  505. * target object.
  506. */
  507. if ((object->reference.class == ACPI_REFCLASS_INDEX) ||
  508. (object->reference.class == ACPI_REFCLASS_NAME)) {
  509. next_object = object->reference.object;
  510. }
  511. break;
  512. case ACPI_TYPE_REGION:
  513. default:
  514. break; /* No subobjects for all other types */
  515. }
  516. /*
  517. * Now we can update the count in the main object. This can only
  518. * happen after we update the sub-objects in case this causes the
  519. * main object to be deleted.
  520. */
  521. acpi_ut_update_ref_count(object, action);
  522. object = NULL;
  523. /* Move on to the next object to be updated */
  524. if (next_object) {
  525. object = next_object;
  526. next_object = NULL;
  527. } else if (state_list) {
  528. state = acpi_ut_pop_generic_state(&state_list);
  529. object = state->update.object;
  530. acpi_ut_delete_generic_state(state);
  531. }
  532. }
  533. return (AE_OK);
  534. error_exit:
  535. ACPI_EXCEPTION((AE_INFO, status,
  536. "Could not update object reference count"));
  537. /* Free any stacked Update State objects */
  538. while (state_list) {
  539. state = acpi_ut_pop_generic_state(&state_list);
  540. acpi_ut_delete_generic_state(state);
  541. }
  542. return (status);
  543. }
  544. /*******************************************************************************
  545. *
  546. * FUNCTION: acpi_ut_add_reference
  547. *
  548. * PARAMETERS: object - Object whose reference count is to be
  549. * incremented
  550. *
  551. * RETURN: None
  552. *
  553. * DESCRIPTION: Add one reference to an ACPI object
  554. *
  555. ******************************************************************************/
  556. void acpi_ut_add_reference(union acpi_operand_object *object)
  557. {
  558. ACPI_FUNCTION_NAME(ut_add_reference);
  559. /* Ensure that we have a valid object */
  560. if (!acpi_ut_valid_internal_object(object)) {
  561. return;
  562. }
  563. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  564. "Obj %p Current Refs=%X [To Be Incremented]\n",
  565. object, object->common.reference_count));
  566. /* Increment the reference count */
  567. (void)acpi_ut_update_object_reference(object, REF_INCREMENT);
  568. return;
  569. }
  570. /*******************************************************************************
  571. *
  572. * FUNCTION: acpi_ut_remove_reference
  573. *
  574. * PARAMETERS: object - Object whose ref count will be decremented
  575. *
  576. * RETURN: None
  577. *
  578. * DESCRIPTION: Decrement the reference count of an ACPI internal object
  579. *
  580. ******************************************************************************/
  581. void acpi_ut_remove_reference(union acpi_operand_object *object)
  582. {
  583. ACPI_FUNCTION_NAME(ut_remove_reference);
  584. /*
  585. * Allow a NULL pointer to be passed in, just ignore it. This saves
  586. * each caller from having to check. Also, ignore NS nodes.
  587. */
  588. if (!object ||
  589. (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED)) {
  590. return;
  591. }
  592. /* Ensure that we have a valid object */
  593. if (!acpi_ut_valid_internal_object(object)) {
  594. return;
  595. }
  596. ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
  597. "Obj %p Current Refs=%X [To Be Decremented]\n",
  598. object, object->common.reference_count));
  599. /*
  600. * Decrement the reference count, and only actually delete the object
  601. * if the reference count becomes 0. (Must also decrement the ref count
  602. * of all subobjects!)
  603. */
  604. (void)acpi_ut_update_object_reference(object, REF_DECREMENT);
  605. return;
  606. }