From 28a8ffbd911012fd53171b11be7b9cc3aa514ea1 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 10 Aug 2017 23:34:00 +0300 Subject: [PATCH] math: handle this ( & 0xff) The recurse_cnt is used to give up on trying to parse too complicated math. There are one or two macros in the kernel that are pages and pages of math and create out of memory issues. But on the other hand, it's really puzzling to see code like: foo = MACRO & 0xff; and Smatch not be able to parse it. And you might have to look really closely at MACRO to see that actually it's a half a page of math when you expand it completely. Anyway, let's treat this as a special case because it's quite important. Signed-off-by: Dan Carpenter --- smatch_math.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/smatch_math.c b/smatch_math.c index 55dc2067..51baf196 100644 --- a/smatch_math.c +++ b/smatch_math.c @@ -343,6 +343,7 @@ static struct range_list *handle_bitwise_AND(struct expression *expr, int implie struct symbol *type; struct range_list *left_rl, *right_rl; sval_t known; + int new_recurse; if (implied != RL_IMPLIED && implied != RL_ABSOLUTE && implied != RL_REAL_ABSOLUTE) return NULL; @@ -368,9 +369,13 @@ static struct range_list *handle_bitwise_AND(struct expression *expr, int implie } } - if (get_implied_value_internal(expr->right, &known, recurse_cnt)) { + if (*recurse_cnt >= 200) + new_recurse = 100; /* Let's try super hard to get the mask */ + if (get_implied_value_internal(expr->right, &known, &new_recurse)) { sval_t min, left_max, mod; + *recurse_cnt = new_recurse; + min = sval_lowest_set_bit(known); right_rl = alloc_rl(min, known); right_rl = cast_rl(type, right_rl); -- 2.11.4.GIT