From 111dd9eedb1e331d5462a19a1111c3a478b8d385 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 5 May 2023 12:28:55 +0300 Subject: [PATCH] locking: use shared success_fail_return() function This change introduces one false positive: fs/ocfs2/dlm/dlmmaster.c:3282 dlm_reset_mleres_owner() warn: inconsistent returns '&dlm->master_lock' Because returning true/false is not necessarily the same as returning success/fail. However, I am willing to live with that for now. Signed-off-by: Dan Carpenter --- check_locking.c | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/check_locking.c b/check_locking.c index a7e88668..41823855 100644 --- a/check_locking.c +++ b/check_locking.c @@ -916,9 +916,6 @@ static int sm_both_locked_and_unlocked(struct sm_state *sm) return is_locked && is_unlocked; } -enum { - ERR_PTR, VALID_PTR, NEGATIVE, ZERO, POSITIVE, NUM_BUCKETS, -}; static bool is_EINTR(struct range_list *rl) { @@ -929,36 +926,6 @@ static bool is_EINTR(struct range_list *rl) return sval.value == -4; } -static int success_fail_positive(struct range_list *rl) -{ - /* void returns are the same as success (zero in the kernel) */ - if (!rl) - return ZERO; - - if (rl_type(rl)->type != SYM_PTR && - !is_whole_rl(rl) && - sval_is_negative(rl_min(rl))) - return NEGATIVE; - - if (rl_min(rl).value == 0 && rl_max(rl).value == 0) - return ZERO; - - if (is_err_ptr(rl_min(rl)) && - is_err_ptr(rl_max(rl))) - return ERR_PTR; - - /* - * Trying to match ERR_PTR(ret) but without the expression struct. - * Ugly... - */ - if (type_bits(&long_ctype) == 64 && - rl_type(rl)->type == SYM_PTR && - rl_min(rl).value == INT_MIN) - return ERR_PTR; - - return POSITIVE; -} - static bool sym_in_lock_table(struct symbol *sym) { int i; @@ -980,6 +947,8 @@ static bool func_in_lock_table(struct expression *expr) return sym_in_lock_table(expr->symbol); } +#define NUM_BUCKETS (RET_UNKNOWN + 1) + static void check_lock(char *name, struct symbol *sym) { struct range_list *locked_lines = NULL; @@ -1023,7 +992,7 @@ static void check_lock(char *name, struct symbol *sym) is_EINTR(estate_rl(return_sm->state))) goto swap_stree; - bucket = success_fail_positive(estate_rl(return_sm->state)); + bucket = success_fail_return(estate_rl(return_sm->state)); if (sm->state == &locked) { add_range(&locked_lines, line, line); locked_buckets[bucket] = true; @@ -1044,11 +1013,8 @@ swap_stree: if (locked_buckets[i] && unlocked_buckets[i]) goto complain; } - if (locked_buckets[NEGATIVE] && - (unlocked_buckets[ZERO] || unlocked_buckets[POSITIVE])) - goto complain; - if (locked_buckets[ERR_PTR]) + if (locked_buckets[RET_FAIL]) goto complain; return; -- 2.11.4.GIT