2 * smatch/check_kunmap.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_slist.h"
15 extern int check_assigned_expr_id
;
18 static void check_assignment(void *data
)
20 struct expression
*expr
= (struct expression
*)data
;
25 if (expr
->type
!= EXPR_CALL
)
27 fn
= expr_to_var(expr
->fn
);
30 if (!strcmp(fn
, "kmap"))
31 sm_msg("warn: passing the wrong stuff kunmap()");
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
;
48 arg
= get_argument_from_call_expr(expr
->args
, 0);
49 sm
= get_sm_state_expr(my_id
, arg
);
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
;
62 arg
= get_argument_from_call_expr(expr
->args
, 0);
63 sm
= get_sm_state_expr(check_assigned_expr_id
, arg
);
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
)
74 if (option_project
!= PROJ_KERNEL
)
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
);