db: store whether functions are global or static
[smatch.git] / check_dma_on_stack.c
blobd0507be6357d558c335f01a77b8b4852a42ed3b2
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 = get_variable_from_expr(arg, NULL);
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 name = get_variable_from_expr(arg, NULL);
38 sm_msg("error: doing dma on the stack (%s)", name);
39 free_string(name);
42 static void register_funcs_from_file(void)
44 struct token *token;
45 const char *func;
46 int arg;
48 token = get_tokens_file("kernel.dma_funcs");
49 if (!token)
50 return;
51 if (token_type(token) != TOKEN_STREAMBEGIN)
52 return;
53 token = token->next;
54 while (token_type(token) != TOKEN_STREAMEND) {
55 if (token_type(token) != TOKEN_IDENT)
56 return;
57 func = show_ident(token->ident);
58 token = token->next;
59 if (token_type(token) != TOKEN_NUMBER)
60 return;
61 arg = atoi(token->number);
62 add_function_hook(func, &match_dma_func, INT_PTR(arg));
63 token = token->next;
65 clear_token_alloc();
68 void check_dma_on_stack(int id)
70 if (option_project != PROJ_KERNEL)
71 return;
72 my_id = id;
73 register_funcs_from_file();