helper: taking the address is not a complicated variable
[smatch.git] / check_input_free_device.c
blob2558dc892530632fa9425b5d6ca686a66721c5ce
1 /*
2 * smatch/check_input_free_device.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
11 * Don't call input_free_device() after calling
12 * input_unregister_device()
16 #include "smatch.h"
17 #include "smatch_slist.h"
19 STATE(no_free);
20 STATE(ok);
22 static int my_id;
24 static void match_assign(struct expression *expr)
26 if (get_state_expr(my_id, expr->left)) {
27 set_state_expr(my_id, expr->left, &ok);
31 static void match_input_unregister(const char *fn, struct expression *expr, void *data)
33 struct expression *arg;
35 arg = get_argument_from_call_expr(expr->args, 0);
36 set_state_expr(my_id, arg, &no_free);
39 static void match_input_free(const char *fn, struct expression *expr, void *data)
41 struct expression *arg;
42 struct sm_state *sm;
44 arg = get_argument_from_call_expr(expr->args, 0);
45 sm = get_sm_state_expr(my_id, arg);
46 if (!sm)
47 return;
48 if (!slist_has_state(sm->possible, &no_free))
49 return;
50 sm_msg("error: don't call input_free_device() after input_unregister_device()");
53 void check_input_free_device(int id)
55 my_id = id;
56 if (option_project != PROJ_KERNEL)
57 return;
58 add_hook(&match_assign, ASSIGNMENT_HOOK);
59 add_function_hook("input_unregister_device", &match_input_unregister, NULL);
60 add_function_hook("input_free_device", &match_input_free, NULL);