Powered by Linux
Re: Better handling of always true conditions. — Semantic Matching Tool

Re: Better handling of always true conditions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have re-written your test.c file and written a patch:

------------------------
#include "check_debug.h"

struct mutex;
void mutex_lock(struct mutex *);
void mutex_unlock(struct mutex *);

void test_func(void)
{
	int lock = 0;
	struct mutex a_mutex;

	mutex_lock(&a_mutex);
	lock = 1;

	if (lock)
		mutex_unlock(&a_mutex);
	__smatch_states("check_locking");
}

diff --git a/check_locking.c b/check_locking.c
index d74ba9e..0d9ae01 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);
 }
--
To unsubscribe from this list: send the line "unsubscribe smatch" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux