4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * The kernel has a small stack so putting huge structs and arrays on the
20 static int total_size
;
22 static int max_lineno
;
23 static int complained
;
25 #define MAX_ALLOWED 1000
27 static void scope_end(int size
)
32 static void match_declarations(struct symbol
*sym
)
37 base
= get_base_type(sym
);
38 if (sym
->ctype
.modifiers
& MOD_STATIC
)
40 name
= sym
->ident
->name
;
41 total_size
+= base
->bit_size
;
42 if (total_size
> max_size
) {
43 max_size
= total_size
;
44 max_lineno
= get_lineno();
46 if (base
->bit_size
>= MAX_ALLOWED
* 8) {
48 sm_msg("warn: '%s' puts %d bytes on stack", name
, base
->bit_size
/ 8);
50 add_scope_hook((scope_hook
*)&scope_end
, INT_PTR(base
->bit_size
));
53 static void match_end_func(struct symbol
*sym
)
58 if ((max_size
>= MAX_ALLOWED
* 8) && !complained
) {
59 sm_printf("%s:%d %s() ", get_filename(), max_lineno
, get_function());
60 sm_printf("warn: function puts %d bytes on stack\n", max_size
/ 8);
68 void check_stack(int id
)
70 if (option_project
!= PROJ_KERNEL
|| !option_spammy
)
74 add_hook(&match_declarations
, DECLARATION_HOOK
);
75 add_hook(&match_end_func
, END_FUNC_HOOK
);