kernel: parse ATOMIC_SET() manually
[smatch.git] / check_input_free_device.c
blobe863958e5688a04b153d46af9f9c54a2968d9476
1 /*
2 * Copyright (C) 2010 Dan Carpenter.
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 * Don't call input_free_device() after calling
20 * input_unregister_device()
24 #include "smatch.h"
25 #include "smatch_slist.h"
27 STATE(no_free);
28 STATE(ok);
30 static int my_id;
32 static void match_assign(struct expression *expr)
34 if (get_state_expr(my_id, expr->left)) {
35 set_state_expr(my_id, expr->left, &ok);
39 static void match_input_unregister(const char *fn, struct expression *expr, void *data)
41 struct expression *arg;
43 arg = get_argument_from_call_expr(expr->args, 0);
44 set_state_expr(my_id, arg, &no_free);
47 static void match_input_free(const char *fn, struct expression *expr, void *data)
49 struct expression *arg;
50 struct sm_state *sm;
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_msg("error: don't call input_free_device() after input_unregister_device()");
61 void check_input_free_device(int id)
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);