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 #include "smatch_slist.h"
25 static void check_assignment(void *data
)
27 struct expression
*expr
= (struct expression
*)data
;
32 if (expr
->type
!= EXPR_CALL
)
34 fn
= expr_to_var(expr
->fn
);
37 if (!strcmp(fn
, "kmap"))
38 sm_warning("passing the wrong variable to kunmap()");
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
;
55 arg
= get_argument_from_call_expr(expr
->args
, 0);
56 sm
= get_sm_state_expr(my_id
, arg
);
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
;
69 arg
= get_argument_from_call_expr(expr
->args
, 0);
70 sm
= get_sm_state_expr(check_assigned_expr_id
, arg
);
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
)
81 if (option_project
!= PROJ_KERNEL
)
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
);