xref: /linux/drivers/acpi/acpica/pswalk.c (revision a8b70ccf10e38775785d9cb12ead916474549f99)
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
3  *
4  * Module Name: pswalk - Parser routines to walk parsed op tree(s)
5  *
6  * Copyright (C) 2000 - 2018, Intel Corp.
7  *
8  *****************************************************************************/
9 
10 #include <acpi/acpi.h>
11 #include "accommon.h"
12 #include "acparser.h"
13 
14 #define _COMPONENT          ACPI_PARSER
15 ACPI_MODULE_NAME("pswalk")
16 
17 /*******************************************************************************
18  *
19  * FUNCTION:    acpi_ps_delete_parse_tree
20  *
21  * PARAMETERS:  subtree_root        - Root of tree (or subtree) to delete
22  *
23  * RETURN:      None
24  *
25  * DESCRIPTION: Delete a portion of or an entire parse tree.
26  *
27  ******************************************************************************/
28 void acpi_ps_delete_parse_tree(union acpi_parse_object *subtree_root)
29 {
30 	union acpi_parse_object *op = subtree_root;
31 	union acpi_parse_object *next = NULL;
32 	union acpi_parse_object *parent = NULL;
33 
34 	ACPI_FUNCTION_TRACE_PTR(ps_delete_parse_tree, subtree_root);
35 
36 	/* Visit all nodes in the subtree */
37 
38 	while (op) {
39 
40 		/* Check if we are not ascending */
41 
42 		if (op != parent) {
43 
44 			/* Look for an argument or child of the current op */
45 
46 			next = acpi_ps_get_arg(op, 0);
47 			if (next) {
48 
49 				/* Still going downward in tree (Op is not completed yet) */
50 
51 				op = next;
52 				continue;
53 			}
54 		}
55 
56 		/* No more children, this Op is complete. */
57 
58 		next = op->common.next;
59 		parent = op->common.parent;
60 
61 		acpi_ps_free_op(op);
62 
63 		/* If we are back to the starting point, the walk is complete. */
64 
65 		if (op == subtree_root) {
66 			return_VOID;
67 		}
68 
69 		if (next) {
70 			op = next;
71 		} else {
72 			op = parent;
73 		}
74 	}
75 
76 	return_VOID;
77 }
78