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