atomic_inc_dec: add this to check_list.h
[smatch.git] / check_kunmap.c
blobfd5addc2d9e39236809ce51819346104868a11b7
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
18 #include "smatch.h"
19 #include "smatch_slist.h"
21 STATE(no_unmap);
23 static int my_id;
25 static void check_assignment(void *data)
27 struct expression *expr = (struct expression *)data;
28 char *fn;
30 if (!expr)
31 return;
32 if (expr->type != EXPR_CALL)
33 return;
34 fn = expr_to_var(expr->fn);
35 if (!fn)
36 return;
37 if (!strcmp(fn, "kmap"))
38 sm_warning("passing the wrong variable to kunmap()");
39 free_string(fn);
42 static void match_kmap_atomic(const char *fn, struct expression *expr, void *data)
44 struct expression *arg;
46 arg = get_argument_from_call_expr(expr->args, 0);
47 set_state_expr(my_id, arg, &no_unmap);
50 static void match_kunmap_atomic(const char *fn, struct expression *expr, void *data)
52 struct expression *arg;
53 struct sm_state *sm;
55 arg = get_argument_from_call_expr(expr->args, 0);
56 sm = get_sm_state_expr(my_id, arg);
57 if (!sm)
58 return;
59 if (slist_has_state(sm->possible, &no_unmap))
60 sm_warning("passing the wrong variable to kmap_atomic()");
63 static void match_kunmap(const char *fn, struct expression *expr, void *data)
65 struct expression *arg;
66 struct sm_state *sm;
67 struct sm_state *tmp;
69 arg = get_argument_from_call_expr(expr->args, 0);
70 sm = get_sm_state_expr(check_assigned_expr_id, arg);
71 if (!sm)
72 return;
73 FOR_EACH_PTR(sm->possible, tmp) {
74 check_assignment(tmp->state->data);
75 } END_FOR_EACH_PTR(tmp);
78 void check_kunmap(int id)
80 my_id = id;
81 if (option_project != PROJ_KERNEL)
82 return;
83 add_function_hook("kunmap", &match_kunmap, NULL);
84 add_function_hook("kmap_atomic", &match_kmap_atomic, NULL);
85 add_function_hook("kunmap_atomic", &match_kunmap_atomic, NULL);