kernel.return_fixes: add mipi_dsi_device_transfer(), timer_delete() and get_device()
[smatch.git] / check_dereferences_param.c
blobc7b5e1713fdc954fa69c1a0790745a1d4a312d14
1 /*
2 * Copyright (C) 2012 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * This is an --info recipe. The goal is to print a message for every parameter
20 * which we can not avoid dereferencing. This is maybe a bit restrictive but it
21 * avoids some false positives.
24 #include "smatch.h"
25 #include "smatch_extra.h"
26 #include "smatch_slist.h"
28 static int my_id;
30 STATE(derefed);
32 static void process_states(void)
34 struct sm_state *tmp;
35 int arg;
36 const char *name;
38 FOR_EACH_MY_SM(my_id, __get_cur_stree(), tmp) {
39 if (tmp->state != &derefed)
40 continue;
41 arg = get_param_num_from_sym(tmp->sym);
42 if (arg < 0)
43 continue;
44 name = get_param_name(tmp);
45 if (!name || name[0] == '&')
46 continue;
47 sql_insert_return_implies(DEREFERENCE, arg, name, "1");
48 } END_FOR_EACH_SM(tmp);
51 static void deref_hook(struct expression *expr)
53 char *param_name = NULL;
54 struct symbol *sym, *param_sym;
55 char *name;
57 name = expr_to_var_sym(expr, &sym);
58 if (!name)
59 return;
61 param_name = get_param_var_sym_var_sym(name, sym, NULL, &param_sym);
62 if (!param_name || !param_sym)
63 goto free;
64 if (get_param_num_from_sym(param_sym) < 0)
65 goto free;
66 if (param_was_set_var_sym(param_name, param_sym))
67 goto free;
69 set_state(my_id, param_name, param_sym, &derefed);
70 free:
71 free_string(name);
74 void check_dereferences_param(int id)
76 my_id = id;
78 add_dereference_hook(deref_hook);
79 all_return_states_hook(&process_states);