double_checking: fix compile problem
[smatch.git] / check_dma_on_stack.c
blob6b49ba99b2541a1b29b3a8893e5730bb7d906f3f
1 /*
2 * sparse/check_dma_on_stack.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_dma_func(const char *fn, struct expression *expr, void *param)
16 struct expression *arg;
17 struct symbol *sym;
18 char *name;
20 arg = get_argument_from_call_expr(expr->args, PTR_INT(param));
21 arg = strip_expr(arg);
22 if (!arg)
23 return;
24 if (arg->type == EXPR_PREOP && arg->op == '&') {
25 if (arg->unop->type != EXPR_SYMBOL)
26 return;
27 name = expr_to_str(arg);
28 sm_msg("error: doing dma on the stack (%s)", name);
29 free_string(name);
30 return;
32 if (arg->type != EXPR_SYMBOL)
33 return;
34 sym = get_type(arg);
35 if (!sym || sym->type != SYM_ARRAY)
36 return;
37 if (get_param_num(arg) >= 0)
38 return;
39 name = expr_to_var(arg);
40 sm_msg("error: doing dma on the stack (%s)", name);
41 free_string(name);
44 static void register_funcs_from_file(void)
46 struct token *token;
47 const char *func;
48 int arg;
50 token = get_tokens_file("kernel.dma_funcs");
51 if (!token)
52 return;
53 if (token_type(token) != TOKEN_STREAMBEGIN)
54 return;
55 token = token->next;
56 while (token_type(token) != TOKEN_STREAMEND) {
57 if (token_type(token) != TOKEN_IDENT)
58 return;
59 func = show_ident(token->ident);
60 token = token->next;
61 if (token_type(token) != TOKEN_NUMBER)
62 return;
63 arg = atoi(token->number);
64 add_function_hook(func, &match_dma_func, INT_PTR(arg));
65 token = token->next;
67 clear_token_alloc();
70 void check_dma_on_stack(int id)
72 if (option_project != PROJ_KERNEL)
73 return;
74 my_id = id;
75 register_funcs_from_file();