db: fixup_kernel.sh: say that we only have 64 CPUs
[smatch.git] / check_dma_on_stack.c
blobf1d15c6c370a8cf2f8409f33cf2078fec25de6b4
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 name = expr_to_var(arg);
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();