From 4cb0d95fc075cc5b69e360e8b3ce22e8dfd9efb1 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Mon, 9 Aug 2021 10:22:25 +0800 Subject: [PATCH] board_inspector: try mroe type convertions when evaluating branch conditions In commit e5ba06cbe80a ("board_inspector: a workaround to an incorrect interpretation") a workaround is introduced to check the data type of predicate operands. That commit assumes that both operands must be exactly integers, which is not usually the case as operation fields or strings can also be used in predicates. This patch applies the following conversions on both operands when evaluating a predicate: 1. Try converting both operands to integers 2. If either conversion in step 1 fails, try regarding both operands as strings. 3. If either operand is not a string, return the default result (i.e. False). Fixes: e5ba06cbe80a ("board_inspector: a workaround to an incorrect interpretation") Tracked-On: #6287 Signed-off-by: Junjie Mao --- .../board_inspector/acpiparser/aml/interpreter.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py b/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py index 3c9d5d362..7e6893245 100644 --- a/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py +++ b/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py @@ -398,10 +398,13 @@ class ConcreteInterpreter(Interpreter): # # As a workaround, check if both the left and right hand sides are integers first. If either is not the case, # the condition is evaluated to False. - if isinstance(lhs, Integer) and isinstance(rhs, Integer): - res = Integer(op(lhs.get(), rhs.get())) - else: - res = Integer(0) + try: + res = Integer(op(lhs.to_integer().get(), rhs.to_integer().get())) + except NotImplementedError: + if isinstance(lhs, String) and isinstance(rhs, String): + res = Integer(op(lhs.get(), rhs.get())) + else: + res = Integer(0) if len(tree.children) >= 3: target = self.interpret(tree.children[2]) if target: