extra: move some code out of match_comparison()
[smatch.git] / check_kunmap.c
blob22478af52420b6a2c0e95adca6063e5ba493c5f6
1 /*
2 * smatch/check_kunmap.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_slist.h"
13 STATE(no_unmap);
15 extern int check_assigned_expr_id;
16 static int my_id;
18 static void check_assignment(void *data)
20 struct expression *expr = (struct expression *)data;
21 char *fn;
23 if (!expr)
24 return;
25 if (expr->type != EXPR_CALL)
26 return;
27 fn = get_variable_from_expr(expr->fn, NULL);
28 if (!fn)
29 return;
30 if (!strcmp(fn, "kmap"))
31 sm_msg("warn: passing the wrong stuff kunmap()");
32 free_string(fn);
35 static void match_kmap_atomic(const char *fn, struct expression *expr, void *data)
37 struct expression *arg;
39 arg = get_argument_from_call_expr(expr->args, 0);
40 set_state_expr(my_id, arg, &no_unmap);
43 static void match_kunmap_atomic(const char *fn, struct expression *expr, void *data)
45 struct expression *arg;
46 struct sm_state *sm;
48 arg = get_argument_from_call_expr(expr->args, 0);
49 sm = get_sm_state_expr(my_id, arg);
50 if (!sm)
51 return;
52 if (slist_has_state(sm->possible, &no_unmap))
53 sm_msg("warn: passing the wrong stuff to kmap_atomic()");
56 static void match_kunmap(const char *fn, struct expression *expr, void *data)
58 struct expression *arg;
59 struct sm_state *sm;
60 struct sm_state *tmp;
62 arg = get_argument_from_call_expr(expr->args, 0);
63 sm = get_sm_state_expr(check_assigned_expr_id, arg);
64 if (!sm)
65 return;
66 FOR_EACH_PTR(sm->possible, tmp) {
67 check_assignment(tmp->state->data);
68 } END_FOR_EACH_PTR(tmp);
71 void check_kunmap(int id)
73 my_id = id;
74 if (option_project != PROJ_KERNEL)
75 return;
76 add_function_hook("kunmap", &match_kunmap, NULL);
77 add_function_hook("kmap_atomic", &match_kmap_atomic, NULL);
78 add_function_hook("kunmap_atomic", &match_kunmap_atomic, NULL);