From 34211c67c4e993d166be1a5710f32c39db8793e6 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 23 Feb 2009 20:40:31 +0300 Subject: [PATCH] Improve lock check output. Add more validation samples. Signed-off-by: Dan Carpenter --- check_locking.c | 4 ++-- validation/sm_locking2.c | 37 +++++++++++++++++++++++++++++++++++++ validation/sm_locking3.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 validation/sm_locking2.c create mode 100644 validation/sm_locking3.c diff --git a/check_locking.c b/check_locking.c index b257af9e..24968f04 100644 --- a/check_locking.c +++ b/check_locking.c @@ -179,14 +179,14 @@ static void match_call(struct expression *expr) if (!sm) add_tracker(&starts_unlocked, lock_name, my_id, NULL); if (sm && slist_has_state(sm->possible, &locked)) - smatch_msg("double lock."); + smatch_msg("double lock '%s'", lock_name); set_state(lock_name, my_id, NULL, &locked); } else if ((lock_name = match_unlock_func(fn_name, expr->args))) { sm = get_sm_state(lock_name, my_id, NULL); if (!sm) add_tracker(&starts_locked, lock_name, my_id, NULL); if (sm && slist_has_state(sm->possible, &unlocked)) - smatch_msg("double unlock."); + smatch_msg("double unlock '%s'", lock_name); set_state(lock_name, my_id, NULL, &unlocked); } else check_locks_needed(fn_name); diff --git a/validation/sm_locking2.c b/validation/sm_locking2.c new file mode 100644 index 00000000..6ec1f039 --- /dev/null +++ b/validation/sm_locking2.c @@ -0,0 +1,37 @@ +void _spin_lock(int name); +void _spin_unlock(int name); +int _spin_trylock(int name); + +int a; +int b; +int func (void) +{ + int mylock = 1; + int mylock2 = 1; + int mylock3 = 1; + + if (!_spin_trylock(mylock)) { + return; + } + + _spin_unlock(mylock); + _spin_unlock(mylock2); + + if (a) + _spin_unlock(mylock); + _spin_lock(mylock2); + + if (!_spin_trylock(mylock3)) + return; + return; +} + +/* + * check-name: Locking #2 + * check-command: smatch sm_locking2.c + * + * check-output-start +sm_locking2.c +21 func(14) double unlock 'mylock' +sm_locking2.c +26 func(19) Lock 'mylock3' held on line 26 but not on 25. + * check-output-end + */ diff --git a/validation/sm_locking3.c b/validation/sm_locking3.c new file mode 100644 index 00000000..922cc4ef --- /dev/null +++ b/validation/sm_locking3.c @@ -0,0 +1,30 @@ +_spin_trylock(int name); +_spin_lock(int name); +_spin_unlock(int name); + +int func (void) +{ + int mylock = 1; + + if (!({frob(); frob(); _spin_trylock(mylock);})) + return; + + frob(); + _spin_unlock(mylock); + + if (((_spin_trylock(mylock)?1:0)?1:0)) + return; + frob_somemore(); + _spin_unlock(mylock); + + return; +} +/* + * check-name: Locking #3 + * check-command: smatch sm_locking3.c + * + * check-output-start +sm_locking3.c +18 func(13) double unlock 'mylock' +sm_locking3.c +20 func(15) Lock 'mylock' held on line 16 but not on 20. + * check-output-end + */ -- 2.11.4.GIT