1 /*
2 * Copyright (C) 2010 Dan Carpenter.
3 *
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.
8 *
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.
13 *
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
16 */
17
18 /*
19 * Don't call input_free_device() after calling
20 * input_unregister_device()
21 *
22 */
23
24 #include "smatch.h"
25 #include "smatch_slist.h"
26
27 STATE(no_free);
28 STATE(ok);
29
30 static int my_id;
31
match_assign(struct expression * expr)32 static void match_assign(struct expression *expr)
33 {
34 if (get_state_expr(my_id, expr->left)) {
35 set_state_expr(my_id, expr->left, &ok);
36 }
37 }
38
match_input_unregister(const char * fn,struct expression * expr,void * data)39 static void match_input_unregister(const char *fn, struct expression *expr, void *data)
40 {
41 struct expression *arg;
42
43 arg = get_argument_from_call_expr(expr->args, 0);
44 set_state_expr(my_id, arg, &no_free);
45 }
46
match_input_free(const char * fn,struct expression * expr,void * data)47 static void match_input_free(const char *fn, struct expression *expr, void *data)
48 {
49 struct expression *arg;
50 struct sm_state *sm;
51
52 arg = get_argument_from_call_expr(expr->args, 0);
53 sm = get_sm_state_expr(my_id, arg);
54 if (!sm)
55 return;
56 if (!slist_has_state(sm->possible, &no_free))
57 return;
58 sm_error("don't call input_free_device() after input_unregister_device()");
59 }
60
check_input_free_device(int id)61 void check_input_free_device(int id)
62 {
63 my_id = id;
64 if (option_project != PROJ_KERNEL)
65 return;
66 add_hook(&match_assign, ASSIGNMENT_HOOK);
67 add_function_hook("input_unregister_device", &match_input_unregister, NULL);
68 add_function_hook("input_free_device", &match_input_free, NULL);
69 }
70