type: fix "strange non-value function or array" warnings
[smatch.git] / check_kunmap.c
blob68ceae45797139413796e3765d8eeccd774817da
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 extern int check_assigned_expr_id;
24 static int my_id;
26 static void check_assignment(void *data)
28 struct expression *expr = (struct expression *)data;
29 char *fn;
31 if (!expr)
32 return;
33 if (expr->type != EXPR_CALL)
34 return;
35 fn = expr_to_var(expr->fn);
36 if (!fn)
37 return;
38 if (!strcmp(fn, "kmap"))
39 sm_msg("warn: passing the wrong variable to kunmap()");
40 free_string(fn);
43 static void match_kmap_atomic(const char *fn, struct expression *expr, void *data)
45 struct expression *arg;
47 arg = get_argument_from_call_expr(expr->args, 0);
48 set_state_expr(my_id, arg, &no_unmap);
51 static void match_kunmap_atomic(const char *fn, struct expression *expr, void *data)
53 struct expression *arg;
54 struct sm_state *sm;
56 arg = get_argument_from_call_expr(expr->args, 0);
57 sm = get_sm_state_expr(my_id, arg);
58 if (!sm)
59 return;
60 if (slist_has_state(sm->possible, &no_unmap))
61 sm_msg("warn: passing the wrong variable to kmap_atomic()");
64 static void match_kunmap(const char *fn, struct expression *expr, void *data)
66 struct expression *arg;
67 struct sm_state *sm;
68 struct sm_state *tmp;
70 arg = get_argument_from_call_expr(expr->args, 0);
71 sm = get_sm_state_expr(check_assigned_expr_id, arg);
72 if (!sm)
73 return;
74 FOR_EACH_PTR(sm->possible, tmp) {
75 check_assignment(tmp->state->data);
76 } END_FOR_EACH_PTR(tmp);
79 void check_kunmap(int id)
81 my_id = id;
82 if (option_project != PROJ_KERNEL)
83 return;
84 add_function_hook("kunmap", &match_kunmap, NULL);
85 add_function_hook("kmap_atomic", &match_kmap_atomic, NULL);
86 add_function_hook("kunmap_atomic", &match_kunmap_atomic, NULL);