From b1d689fa87a5a0a27f8e4f9dbcc935129586f9c3 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 26 May 2020 16:04:58 +0300 Subject: [PATCH] atomic_inc_dec: add more functions This just adds more functions which do reference counting. Signed-off-by: Dan Carpenter --- check_atomic_inc_dec.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/check_atomic_inc_dec.c b/check_atomic_inc_dec.c index 9eef31f0..7b75b588 100644 --- a/check_atomic_inc_dec.c +++ b/check_atomic_inc_dec.c @@ -242,6 +242,23 @@ static void refcount_dec(const char *fn, struct expression *expr, void *param) db_inc_dec(expr, PTR_INT(param), "$->ref.counter", "", ATOMIC_DEC); } +static void pm_runtime_get_sync(const char *fn, struct expression *expr, void *param) +{ + db_inc_dec(expr, PTR_INT(param), "$->power.usage_count.counter", "", ATOMIC_INC); +} + +static void match_implies_inc(const char *fn, struct expression *call_expr, + struct expression *assign_expr, void *param) +{ + db_inc_dec(call_expr, PTR_INT(param), "$->ref.counter", "", ATOMIC_INC); +} + +static void match_implies_atomic_dec(const char *fn, struct expression *call_expr, + struct expression *assign_expr, void *param) +{ + db_inc_dec(call_expr, PTR_INT(param), "$->counter", "", ATOMIC_DEC); +} + static void match_return_info(int return_id, char *return_ranges, struct expression *expr) { struct sm_state *sm; @@ -402,9 +419,14 @@ void check_atomic_inc_dec(int id) add_function_hook("atomic_add_return", &match_atomic_add, NULL); add_function_hook("atomic_sub_return", &match_atomic_sub, NULL); add_function_hook("atomic_sub_and_test", &match_atomic_sub, NULL); + add_function_hook("atomic_long_sub_and_test", &match_atomic_sub, NULL); + add_function_hook("atomic64_sub_and_test", &match_atomic_sub, NULL); add_function_hook("atomic_dec_and_test", &match_atomic_dec, NULL); + add_function_hook("atomic_long_dec_and_test", &match_atomic_dec, NULL); + add_function_hook("atomic64_dec_and_test", &match_atomic_dec, NULL); add_function_hook("_atomic_dec_and_lock", &match_atomic_dec, NULL); add_function_hook("atomic_dec", &match_atomic_dec, NULL); + add_function_hook("atomic_dec_return", &match_atomic_dec, NULL); add_function_hook("atomic_long_inc", &match_atomic_inc, NULL); add_function_hook("atomic_long_dec", &match_atomic_dec, NULL); add_function_hook("atomic_inc", &match_atomic_inc, NULL); @@ -413,11 +435,17 @@ void check_atomic_inc_dec(int id) add_function_hook("refcount_inc", &refcount_inc, INT_PTR(0)); add_function_hook("refcount_dec", &refcount_dec, INT_PTR(0)); add_function_hook("refcount_add", &refcount_inc, INT_PTR(1)); - add_function_hook("refcount_add_not_zero", &refcount_inc, INT_PTR(1)); - add_function_hook("refcount_inc_not_zero", &refcount_inc, INT_PTR(0)); + + return_implies_state("refcount_add_not_zero", 1, 1, &match_implies_inc, INT_PTR(1)); + return_implies_state("refcount_inc_not_zero", 1, 1, &match_implies_inc, INT_PTR(0)); + + return_implies_state("atomic_dec_if_positive", 0, INT_MAX, &match_implies_atomic_dec, INT_PTR(0)); + add_function_hook("refcount_sub_and_test", &refcount_dec, INT_PTR(1)); add_function_hook("refcount_dec_and_test", &refcount_dec, INT_PTR(0)); + add_function_hook("pm_runtime_get_sync", &pm_runtime_get_sync, INT_PTR(0)); + add_hook(&match_check_missed, END_FUNC_HOOK); add_hook(&match_after_func, AFTER_FUNC_HOOK); -- 2.11.4.GIT