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"
23 extern int check_assigned_expr_id
;
26 static void check_assignment(void *data
)
28 struct expression
*expr
= (struct expression
*)data
;
33 if (expr
->type
!= EXPR_CALL
)
35 fn
= expr_to_var(expr
->fn
);
38 if (!strcmp(fn
, "kmap"))
39 sm_msg("warn: passing the wrong variable to kunmap()");
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
;
56 arg
= get_argument_from_call_expr(expr
->args
, 0);
57 sm
= get_sm_state_expr(my_id
, arg
);
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
;
70 arg
= get_argument_from_call_expr(expr
->args
, 0);
71 sm
= get_sm_state_expr(check_assigned_expr_id
, arg
);
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
)
82 if (option_project
!= PROJ_KERNEL
)
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
);