*new* add smatch_data/kernel.silenced_functions to silence common noise
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 18 Dec 2013 15:19:55 +0000 (18 18:19 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Wed, 18 Dec 2013 15:19:55 +0000 (18 18:19 +0300)
There are some very common functions which generate warnings.  It's a bit
tricky to fix smatch to handle them properly so I've just added file to
silence them in an unsubtle way.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch.h
smatch_data/kernel.silenced_functions [new file with mode: 0644]
smatch_project.c

index 012d064..9c1333f 100644 (file)
--- a/smatch.h
+++ b/smatch.h
@@ -163,6 +163,8 @@ extern int final_pass;
 extern struct symbol *cur_func_sym;
 extern int option_debug;
 extern int local_debug;
+extern int option_info;
+int is_silenced_function(void);
 
 extern FILE *sm_outfd;
 #define sm_printf(msg...) do { if (final_pass || option_debug) fprintf(sm_outfd, msg); } while (0)
@@ -179,6 +181,8 @@ do {                                                           \
        print_implied_debug_msg();                             \
        if (!option_debug && !final_pass)                      \
                break;                                         \
+       if (!option_info && is_silenced_function())            \
+               break;                                         \
        sm_prefix();                                           \
         sm_printf(msg);                                        \
         sm_printf("\n");                                       \
@@ -608,7 +612,6 @@ extern int option_no_data;
 extern int option_spammy;
 extern int option_full_path;
 extern int option_param_mapper;
-extern int option_info;
 extern int option_call_tree;
 extern int num_checks;
 
diff --git a/smatch_data/kernel.silenced_functions b/smatch_data/kernel.silenced_functions
new file mode 100644 (file)
index 0000000..ffa34af
--- /dev/null
@@ -0,0 +1,7 @@
+/* Don't print anything from these functions */
+atomic_dec_and_test
+atomic_sub_and_test
+test_and_clear_bit
+test_and_set_bit
+__copy_to_user_nocheck
+__copy_from_user_nocheck
index 7b24908..5b9601b 100644 (file)
 
 #include "smatch.h"
 #include "smatch_extra.h"
+#include "smatch_function_hashtable.h"
+
+static DEFINE_HASHTABLE_INSERT(insert_func, char, int);
+static DEFINE_HASHTABLE_SEARCH(search_func, char, int);
+static struct hashtable *silenced_funcs;
+
+int is_silenced_function(void)
+{
+       char *func;
+
+       func = get_function();
+       if (!func)
+               return 0;
+       if (search_func(silenced_funcs, func))
+               return 1;
+       return 0;
+}
 
 static void register_no_return_funcs(void)
 {
@@ -71,8 +88,37 @@ static void register_ignored_macros(void)
        clear_token_alloc();
 }
 
+static void register_silenced_functions(void)
+{
+       struct token *token;
+       char *func;
+       char name[256];
+
+       silenced_funcs = create_function_hashtable(500);
+
+       if (option_project == PROJ_NONE)
+               return;
+
+       snprintf(name, 256, "%s.silenced_functions", option_project_str);
+
+       token = get_tokens_file(name);
+       if (!token)
+               return;
+       if (token_type(token) != TOKEN_STREAMBEGIN)
+               return;
+       token = token->next;
+       while (token_type(token) != TOKEN_STREAMEND) {
+               if (token_type(token) != TOKEN_IDENT)
+                       return;
+               func = alloc_string(show_ident(token->ident));
+               insert_func(silenced_funcs, func, INT_PTR(1));
+               token = token->next;
+       }
+       clear_token_alloc();
+}
 void register_project(int id)
 {
        register_no_return_funcs();
        register_ignored_macros();
+       register_silenced_functions();
 }