blob: 5470213b8e645986a3c01b5e0e25ce7961d12dc6 [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*******************************************************************************
3 *
4 * Module Name: nsalloc - Namespace allocation and deletion utilities
5 *
6 ******************************************************************************/
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -05009#include "accommon.h"
10#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040013ACPI_MODULE_NAME("nsalloc")
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015/*******************************************************************************
16 *
17 * FUNCTION: acpi_ns_create_node
18 *
Bob Mooreba494be2012-07-12 09:40:10 +080019 * PARAMETERS: name - Name of the new node (4 char ACPI name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 *
Robert Moore44f6c012005-04-18 22:49:35 -040021 * RETURN: New namespace node (Null on failure)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * DESCRIPTION: Create a namespace node
24 *
25 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040026struct acpi_namespace_node *acpi_ns_create_node(u32 name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Len Brown4be44fc2005-08-05 00:44:28 -040028 struct acpi_namespace_node *node;
Valery A. Podrezovafbb9e62007-02-02 19:48:23 +030029#ifdef ACPI_DBG_TRACK_ALLOCATIONS
30 u32 temp;
31#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Bob Mooreb229cf92006-04-21 17:15:00 -040033 ACPI_FUNCTION_TRACE(ns_create_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Bob Moore616861242006-03-17 16:44:00 -050035 node = acpi_os_acquire_object(acpi_gbl_namespace_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -040037 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 }
39
Len Brown4be44fc2005-08-05 00:44:28 -040040 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Valery A. Podrezovafbb9e62007-02-02 19:48:23 +030042#ifdef ACPI_DBG_TRACK_ALLOCATIONS
Bob Moored4913dc2009-03-06 10:05:18 +080043 temp = acpi_gbl_ns_node_list->total_allocated -
Valery A. Podrezovafbb9e62007-02-02 19:48:23 +030044 acpi_gbl_ns_node_list->total_freed;
45 if (temp > acpi_gbl_ns_node_list->max_occupied) {
46 acpi_gbl_ns_node_list->max_occupied = temp;
47 }
48#endif
49
Len Brown4be44fc2005-08-05 00:44:28 -040050 node->name.integer = name;
Len Brown4be44fc2005-08-05 00:44:28 -040051 ACPI_SET_DESCRIPTOR_TYPE(node, ACPI_DESC_TYPE_NAMED);
Len Brown4be44fc2005-08-05 00:44:28 -040052 return_PTR(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055/*******************************************************************************
56 *
57 * FUNCTION: acpi_ns_delete_node
58 *
Bob Mooreba494be2012-07-12 09:40:10 +080059 * PARAMETERS: node - Node to be deleted
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * RETURN: None
62 *
Bob Moore8e4319c2009-06-29 13:43:27 +080063 * DESCRIPTION: Delete a namespace node. All node deletions must come through
64 * here. Detaches any attached objects, including any attached
65 * data. If a handler is associated with attached data, it is
66 * invoked before the node is deleted.
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 *
68 ******************************************************************************/
69
Len Brown4be44fc2005-08-05 00:44:28 -040070void acpi_ns_delete_node(struct acpi_namespace_node *node)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Bob Moore8e4319c2009-06-29 13:43:27 +080072 union acpi_operand_object *obj_desc;
Tomasz Nowicki794ba092013-11-21 12:19:55 +080073 union acpi_operand_object *next_desc;
Bob Moore8e4319c2009-06-29 13:43:27 +080074
75 ACPI_FUNCTION_NAME(ns_delete_node);
76
77 /* Detach an object if there is one */
78
79 acpi_ns_detach_object(node);
80
81 /*
Tomasz Nowicki794ba092013-11-21 12:19:55 +080082 * Delete an attached data object list if present (objects that were
83 * attached via acpi_attach_data). Note: After any normal object is
84 * detached above, the only possible remaining object(s) are data
85 * objects, in a linked list.
Bob Moore8e4319c2009-06-29 13:43:27 +080086 */
87 obj_desc = node->object;
Tomasz Nowicki794ba092013-11-21 12:19:55 +080088 while (obj_desc && (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) {
Bob Moore8e4319c2009-06-29 13:43:27 +080089
90 /* Invoke the attached data deletion handler if present */
91
92 if (obj_desc->data.handler) {
93 obj_desc->data.handler(node, obj_desc->data.pointer);
94 }
95
Tomasz Nowicki794ba092013-11-21 12:19:55 +080096 next_desc = obj_desc->common.next_object;
Bob Moore8e4319c2009-06-29 13:43:27 +080097 acpi_ut_remove_reference(obj_desc);
Tomasz Nowicki794ba092013-11-21 12:19:55 +080098 obj_desc = next_desc;
Bob Moore8e4319c2009-06-29 13:43:27 +080099 }
100
Bob Moore3f69fe12013-11-21 12:20:06 +0800101 /* Special case for the statically allocated root node */
102
103 if (node == acpi_gbl_root_node) {
104 return;
105 }
106
Bob Moore8e4319c2009-06-29 13:43:27 +0800107 /* Now we can delete the node */
108
109 (void)acpi_os_release_object(acpi_gbl_namespace_cache, node);
110
111 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_freed++);
112 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Node %p, Remaining %X\n",
113 node, acpi_gbl_current_node_count));
114}
115
116/*******************************************************************************
117 *
118 * FUNCTION: acpi_ns_remove_node
119 *
Bob Mooreba494be2012-07-12 09:40:10 +0800120 * PARAMETERS: node - Node to be removed/deleted
Bob Moore8e4319c2009-06-29 13:43:27 +0800121 *
122 * RETURN: None
123 *
124 * DESCRIPTION: Remove (unlink) and delete a namespace node
125 *
126 ******************************************************************************/
127
128void acpi_ns_remove_node(struct acpi_namespace_node *node)
129{
Len Brown4be44fc2005-08-05 00:44:28 -0400130 struct acpi_namespace_node *parent_node;
131 struct acpi_namespace_node *prev_node;
132 struct acpi_namespace_node *next_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Bob Moore8e4319c2009-06-29 13:43:27 +0800134 ACPI_FUNCTION_TRACE_PTR(ns_remove_node, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800136 parent_node = node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 prev_node = NULL;
139 next_node = parent_node->child;
140
141 /* Find the node that is the previous peer in the parent's child list */
142
143 while (next_node != node) {
144 prev_node = next_node;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800145 next_node = next_node->peer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147
148 if (prev_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 /* Node is not first child, unlink it */
151
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800152 prev_node->peer = node->peer;
Len Brown4be44fc2005-08-05 00:44:28 -0400153 } else {
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800154 /*
155 * Node is first child (has no previous peer).
156 * Link peer list to parent
157 */
158 parent_node->child = node->peer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160
Bob Moore8e4319c2009-06-29 13:43:27 +0800161 /* Delete the node and any attached objects */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Bob Moore8e4319c2009-06-29 13:43:27 +0800163 acpi_ns_delete_node(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 return_VOID;
165}
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167/*******************************************************************************
168 *
169 * FUNCTION: acpi_ns_install_node
170 *
171 * PARAMETERS: walk_state - Current state of the walk
172 * parent_node - The parent of the new Node
Bob Mooreba494be2012-07-12 09:40:10 +0800173 * node - The new Node to install
174 * type - ACPI object type of the new Node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 *
176 * RETURN: None
177 *
178 * DESCRIPTION: Initialize a new namespace node and install it amongst
179 * its peers.
180 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700181 * Note: Current namespace lookup is linear search. This appears
182 * to be sufficient as namespace searches consume only a small
183 * fraction of the execution time of the ACPI subsystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 *
185 ******************************************************************************/
186
Len Brown4be44fc2005-08-05 00:44:28 -0400187void acpi_ns_install_node(struct acpi_walk_state *walk_state, struct acpi_namespace_node *parent_node, /* Parent */
188 struct acpi_namespace_node *node, /* New Child */
189 acpi_object_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Len Brown4be44fc2005-08-05 00:44:28 -0400191 acpi_owner_id owner_id = 0;
192 struct acpi_namespace_node *child_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Bob Mooreb229cf92006-04-21 17:15:00 -0400194 ACPI_FUNCTION_TRACE(ns_install_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 if (walk_state) {
Alexey Starikovskiya9fc0312010-05-26 13:59:51 +0800197 /*
198 * Get the owner ID from the Walk state. The owner ID is used to
199 * track table deletion and deletion of objects created by methods.
200 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 owner_id = walk_state->owner_id;
Alexey Starikovskiya9fc0312010-05-26 13:59:51 +0800202
203 if ((walk_state->method_desc) &&
204 (parent_node != walk_state->method_node)) {
205 /*
206 * A method is creating a new node that is not a child of the
207 * method (it is non-local). Mark the executing method as having
208 * modified the namespace. This is used for cleanup when the
209 * method exits.
210 */
Lin Ming26294842011-01-12 09:19:43 +0800211 walk_state->method_desc->method.info_flags |=
212 ACPI_METHOD_MODIFIED_NAMESPACE;
Alexey Starikovskiya9fc0312010-05-26 13:59:51 +0800213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215
216 /* Link the new entry into the parent and existing children */
217
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800218 node->peer = NULL;
219 node->parent = parent_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 child_node = parent_node->child;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 if (!child_node) {
223 parent_node->child = node;
Len Brown4be44fc2005-08-05 00:44:28 -0400224 } else {
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800225 /* Add node to the end of the peer list */
226
227 while (child_node->peer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 child_node = child_node->peer;
229 }
230
231 child_node->peer = node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233
234 /* Init the new entry */
235
236 node->owner_id = owner_id;
237 node->type = (u8) type;
238
Len Brown4be44fc2005-08-05 00:44:28 -0400239 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
240 "%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n",
241 acpi_ut_get_node_name(node),
242 acpi_ut_get_type_name(node->type), node, owner_id,
243 acpi_ut_get_node_name(parent_node),
244 acpi_ut_get_type_name(parent_node->type),
245 parent_node));
Bob Moore793c2382006-03-31 00:00:00 -0500246
247 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250/*******************************************************************************
251 *
252 * FUNCTION: acpi_ns_delete_children
253 *
254 * PARAMETERS: parent_node - Delete this objects children
255 *
256 * RETURN: None.
257 *
258 * DESCRIPTION: Delete all children of the parent object. In other words,
259 * deletes a "scope".
260 *
261 ******************************************************************************/
262
Len Brown4be44fc2005-08-05 00:44:28 -0400263void acpi_ns_delete_children(struct acpi_namespace_node *parent_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Len Brown4be44fc2005-08-05 00:44:28 -0400265 struct acpi_namespace_node *next_node;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800266 struct acpi_namespace_node *node_to_delete;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Bob Mooreb229cf92006-04-21 17:15:00 -0400268 ACPI_FUNCTION_TRACE_PTR(ns_delete_children, parent_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 if (!parent_node) {
271 return_VOID;
272 }
273
Bob Moored4913dc2009-03-06 10:05:18 +0800274 /* Deallocate all children at this level */
275
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800276 next_node = parent_node->child;
277 while (next_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 /* Grandchildren should have all been deleted already */
280
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800281 if (next_node->child) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500282 ACPI_ERROR((AE_INFO, "Found a grandchild! P=%p C=%p",
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800283 parent_node, next_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
Bob Moore8e4319c2009-06-29 13:43:27 +0800286 /*
287 * Delete this child node and move on to the next child in the list.
288 * No need to unlink the node since we are deleting the entire branch.
289 */
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800290 node_to_delete = next_node;
291 next_node = next_node->peer;
292 acpi_ns_delete_node(node_to_delete);
293 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 /* Clear the parent's child pointer */
296
297 parent_node->child = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 return_VOID;
299}
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301/*******************************************************************************
302 *
303 * FUNCTION: acpi_ns_delete_namespace_subtree
304 *
305 * PARAMETERS: parent_node - Root of the subtree to be deleted
306 *
307 * RETURN: None.
308 *
Bob Moore73a30902012-10-31 02:26:55 +0000309 * DESCRIPTION: Delete a subtree of the namespace. This includes all objects
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 * stored within the subtree.
311 *
312 ******************************************************************************/
313
Len Brown4be44fc2005-08-05 00:44:28 -0400314void acpi_ns_delete_namespace_subtree(struct acpi_namespace_node *parent_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Len Brown4be44fc2005-08-05 00:44:28 -0400316 struct acpi_namespace_node *child_node = NULL;
317 u32 level = 1;
Dana Myers5d3131f2011-01-12 09:09:31 +0800318 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Bob Mooreb229cf92006-04-21 17:15:00 -0400320 ACPI_FUNCTION_TRACE(ns_delete_namespace_subtree);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 if (!parent_node) {
323 return_VOID;
324 }
325
Dana Myers5d3131f2011-01-12 09:09:31 +0800326 /* Lock namespace for possible update */
327
328 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
329 if (ACPI_FAILURE(status)) {
330 return_VOID;
331 }
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 /*
334 * Traverse the tree of objects until we bubble back up
335 * to where we started.
336 */
337 while (level > 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 /* Get the next node in this scope (NULL if none) */
340
Bob Moore8c725bf2009-05-21 10:27:51 +0800341 child_node = acpi_ns_get_next_node(parent_node, child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 if (child_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 /* Found a child node - detach any attached object */
345
Len Brown4be44fc2005-08-05 00:44:28 -0400346 acpi_ns_detach_object(child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 /* Check if this node has any children */
349
Bob Moore8c725bf2009-05-21 10:27:51 +0800350 if (child_node->child) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 /*
352 * There is at least one child of this node,
353 * visit the node
354 */
355 level++;
356 parent_node = child_node;
357 child_node = NULL;
358 }
Len Brown4be44fc2005-08-05 00:44:28 -0400359 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 /*
361 * No more children of this parent node.
362 * Move up to the grandparent.
363 */
364 level--;
365
366 /*
367 * Now delete all of the children of this parent
368 * all at the same time.
369 */
Len Brown4be44fc2005-08-05 00:44:28 -0400370 acpi_ns_delete_children(parent_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 /* New "last child" is this parent node */
373
374 child_node = parent_node;
375
376 /* Move up the tree to the grandparent */
377
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800378 parent_node = parent_node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 }
380 }
381
Dana Myers5d3131f2011-01-12 09:09:31 +0800382 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 return_VOID;
384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386/*******************************************************************************
387 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 * FUNCTION: acpi_ns_delete_namespace_by_owner
389 *
390 * PARAMETERS: owner_id - All nodes with this owner will be deleted
391 *
392 * RETURN: Status
393 *
394 * DESCRIPTION: Delete entries within the namespace that are owned by a
Bob Moore73a30902012-10-31 02:26:55 +0000395 * specific ID. Used to delete entire ACPI tables. All
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 * reference counts are updated.
397 *
Bob Mooref6dd9222006-07-07 20:44:38 -0400398 * MUTEX: Locks namespace during deletion walk.
399 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 ******************************************************************************/
401
Len Brown4be44fc2005-08-05 00:44:28 -0400402void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Len Brown4be44fc2005-08-05 00:44:28 -0400404 struct acpi_namespace_node *child_node;
405 struct acpi_namespace_node *deletion_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400406 struct acpi_namespace_node *parent_node;
Bob Mooref6dd9222006-07-07 20:44:38 -0400407 u32 level;
408 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Bob Mooreb229cf92006-04-21 17:15:00 -0400410 ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Robert Moore0c9938c2005-07-29 15:15:00 -0700412 if (owner_id == 0) {
413 return_VOID;
414 }
415
Bob Mooref6dd9222006-07-07 20:44:38 -0400416 /* Lock namespace for possible update */
417
418 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
419 if (ACPI_FAILURE(status)) {
420 return_VOID;
421 }
422
Bob Moore616861242006-03-17 16:44:00 -0500423 deletion_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400424 parent_node = acpi_gbl_root_node;
425 child_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400426 level = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428 /*
429 * Traverse the tree of nodes until we bubble back up
430 * to where we started.
431 */
432 while (level > 0) {
433 /*
434 * Get the next child of this parent node. When child_node is NULL,
435 * the first child of the parent is returned
436 */
Bob Moore8c725bf2009-05-21 10:27:51 +0800437 child_node = acpi_ns_get_next_node(parent_node, child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 if (deletion_node) {
Bob Moore616861242006-03-17 16:44:00 -0500440 acpi_ns_delete_children(deletion_node);
Bob Moore8e4319c2009-06-29 13:43:27 +0800441 acpi_ns_remove_node(deletion_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 deletion_node = NULL;
443 }
444
445 if (child_node) {
446 if (child_node->owner_id == owner_id) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 /* Found a matching child node - detach any attached object */
449
Len Brown4be44fc2005-08-05 00:44:28 -0400450 acpi_ns_detach_object(child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
452
453 /* Check if this node has any children */
454
Bob Moore8c725bf2009-05-21 10:27:51 +0800455 if (child_node->child) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 /*
457 * There is at least one child of this node,
458 * visit the node
459 */
460 level++;
461 parent_node = child_node;
462 child_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400463 } else if (child_node->owner_id == owner_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 deletion_node = child_node;
465 }
Len Brown4be44fc2005-08-05 00:44:28 -0400466 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 /*
468 * No more children of this parent node.
469 * Move up to the grandparent.
470 */
471 level--;
472 if (level != 0) {
473 if (parent_node->owner_id == owner_id) {
474 deletion_node = parent_node;
475 }
476 }
477
478 /* New "last child" is this parent node */
479
480 child_node = parent_node;
481
482 /* Move up the tree to the grandparent */
483
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800484 parent_node = parent_node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
486 }
487
Bob Mooref6dd9222006-07-07 20:44:38 -0400488 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 return_VOID;
490}