From a5f5ed0865ef2fe2111139251b8edaee0c7ec0ca Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Wed, 21 Jul 2021 13:19:36 +0800 Subject: [PATCH] board_inspector: fix unregisteration of conditionally disabled objects The current ConditionallyUnregisterSymbolVisitor has the following two issues. 1. The visitor will crash when a DefIfElse node is not fully parsed due to failed deferred expansion. 2. Nested DefIfElse of disabled blocks are still checked and one of its branch may still take effect. This patch fixes those issues by checking the predicates of a DefIfElse block only when conditionally_hidden is False and check existence of TermList and DefElse clauses. Tracked-On: #6298 Signed-off-by: Junjie Mao --- .../acpiparser/aml/visitors.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/misc/config_tools/board_inspector/acpiparser/aml/visitors.py b/misc/config_tools/board_inspector/acpiparser/aml/visitors.py index d94de1beb..f64e04981 100644 --- a/misc/config_tools/board_inspector/acpiparser/aml/visitors.py +++ b/misc/config_tools/board_inspector/acpiparser/aml/visitors.py @@ -46,24 +46,26 @@ class ConditionallyUnregisterSymbolVisitor(Visitor): return f def visit_topdown(self, tree): - if tree.label == "DefIfElse": + if not self.conditionally_hidden and tree.label == "DefIfElse": self.context.change_scope(tree.scope) cond = self.interpreter.interpret(tree.children[1]).get() self.context.pop_scope() self.depth += 1 if cond: - self.visit_topdown(tree.children[2]) - if len(tree.children) == 4: + if hasattr(tree, "TermList"): + self.visit_topdown(tree.TermList) + if hasattr(tree, "DefElse") and tree.DefElse: self.conditionally_hidden = True - self.visit_topdown(tree.children[3]) + self.visit_topdown(tree.DefElse) self.conditionally_hidden = False else: - self.conditionally_hidden = True - self.visit_topdown(tree.children[2]) - self.conditionally_hidden = False - if len(tree.children) == 4: - self.visit_topdown(tree.children[3]) + if hasattr(tree, "TermList"): + self.conditionally_hidden = True + self.visit_topdown(tree.TermList) + self.conditionally_hidden = False + if hasattr(tree, "DefElse") and tree.DefElse: + self.visit_topdown(tree.DefElse) self.depth -= 1 elif tree.label not in ["DefMethod"]: super().visit_topdown(tree)