From 229d8131e70249bb3905978ab4425a5929a82795 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 9 Sep 2014 13:03:52 +0300 Subject: [PATCH] locking: remove some duplicate "sometimes locked" warnings We can call this hook several times per each return and for some code it was generating the same warning each time it was called. Just one warning is enough. Signed-off-by: Dan Carpenter --- check_locking.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/check_locking.c b/check_locking.c index e009d675..571a9c75 100644 --- a/check_locking.c +++ b/check_locking.c @@ -567,7 +567,7 @@ static struct locks_on_return *alloc_return(struct expression *expr) return ret; } -static void check_possible(struct sm_state *sm) +static int check_possible(struct sm_state *sm) { struct sm_state *tmp; int islocked = 0; @@ -575,7 +575,7 @@ static void check_possible(struct sm_state *sm) int undef = 0; if (!option_spammy) - return; + return 0; FOR_EACH_PTR(sm->possible, tmp) { if (tmp->state == &locked) @@ -596,10 +596,15 @@ static void check_possible(struct sm_state *sm) if (tmp->state == &undefined) undef = 1; // i don't think this is possible any more. } END_FOR_EACH_PTR(tmp); - if ((islocked && isunlocked) || undef) + if ((islocked && isunlocked) || undef) { sm_msg("warn: '%s' is sometimes locked here and sometimes unlocked.", sm->name); + return 1; + } + return 0; } +static struct position warned_pos; + static void match_return(int return_id, char *return_ranges, struct expression *expr) { struct locks_on_return *ret; @@ -611,6 +616,9 @@ static void match_return(int return_id, char *return_ranges, struct expression * if (__inline_fn) return; + if (expr && cmp_pos(expr->pos, warned_pos) == 0) + return; + ret = alloc_return(expr); stree = __get_cur_stree(); @@ -632,7 +640,10 @@ static void match_return(int return_id, char *return_ranges, struct expression * add_tracker(&ret->unlocked, tmp->owner,tmp->name, tmp->sym); } else { - check_possible(tmp); + if (check_possible(tmp)) { + if (expr) + warned_pos = expr->pos; + } } } END_FOR_EACH_SM(tmp); add_ptr_list(&all_returns, ret); -- 2.11.4.GIT