2 * Copyright (C) 2010 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * The kernel has a small stack so putting huge structs and arrays on the
28 static int total_size
;
30 static int max_lineno
;
31 static int complained
;
33 #define MAX_ALLOWED 1000
35 static void scope_end(int size
)
40 static void match_declarations(struct symbol
*sym
)
45 base
= get_base_type(sym
);
46 if (sym
->ctype
.modifiers
& MOD_STATIC
)
48 name
= sym
->ident
->name
;
49 total_size
+= base
->bit_size
;
50 if (total_size
> max_size
) {
51 max_size
= total_size
;
52 max_lineno
= get_lineno();
54 if (base
->bit_size
>= MAX_ALLOWED
* 8) {
56 sm_msg("warn: '%s' puts %d bytes on stack", name
, base
->bit_size
/ 8);
58 add_scope_hook((scope_hook
*)&scope_end
, INT_PTR(base
->bit_size
));
61 static void match_end_func(struct symbol
*sym
)
66 if ((max_size
>= MAX_ALLOWED
* 8) && !complained
) {
67 sm_printf("%s:%d %s() ", get_filename(), max_lineno
, get_function());
68 sm_printf("warn: function puts %d bytes on stack\n", max_size
/ 8);
76 void check_stack(int id
)
78 if (option_project
!= PROJ_KERNEL
|| !option_spammy
)
82 add_hook(&match_declarations
, DECLARATION_HOOK
);
83 add_hook(&match_end_func
, END_FUNC_HOOK
);