From 1da9d7e1760cda0a06722a007782cac369bb2fc8 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 17 Feb 2016 13:26:25 +0300 Subject: [PATCH] locking: don't warn about impossible paths If we have code like: lock(); var = 1; if (var) unlock(); Then, since we know that var is always set it means we can ignore the false path. Reported-by: Oleg Drokin Signed-off-by: Dan Carpenter --- check_locking.c | 8 ++++++++ validation/sm_locking.c | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/check_locking.c b/check_locking.c index d74ba9e0..0d9ae010 100644 --- a/check_locking.c +++ b/check_locking.c @@ -38,6 +38,7 @@ static int func_has_transition; STATE(locked); STATE(start_state); STATE(unlocked); +STATE(impossible); enum action { LOCK, @@ -439,6 +440,12 @@ static struct smatch_state *unmatched_state(struct sm_state *sm) return &start_state; } +static void pre_merge_hook(struct sm_state *sm) +{ + if (is_impossible_path()) + set_state(my_id, sm->name, sm->sym, &impossible); +} + static void do_lock(const char *name) { struct sm_state *sm; @@ -939,6 +946,7 @@ void check_locking(int id) return; add_unmatched_state_hook(my_id, &unmatched_state); + add_pre_merge_hook(my_id, &pre_merge_hook); add_split_return_callback(match_return); add_hook(&match_func_end, END_FUNC_HOOK); } diff --git a/validation/sm_locking.c b/validation/sm_locking.c index dabb1980..6ba90eeb 100644 --- a/validation/sm_locking.c +++ b/validation/sm_locking.c @@ -1,8 +1,8 @@ _spin_lock(int name); _spin_unlock(int name); -int a; -int b; +int a, b, c; + int func (void) { int mylock = 1; @@ -21,7 +21,7 @@ int func (void) return; } - if (a) + if (c) _spin_lock(mylock3); return; } -- 2.11.4.GIT