2 * Copyright (C) 2012 Oracle.
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 #include "smatch_slist.h"
23 static const char *my_flags
;
25 static void match_function_definition(struct symbol
*sym
)
30 FOR_EACH_PTR(sym
->ctype
.base_type
->arguments
, arg
) {
31 type_str
= pos_ident(arg
->pos
);
32 if (!type_str
|| strcmp(type_str
, "gfp_t") != 0)
34 my_flags
= arg
->ident
->name
;
36 } END_FOR_EACH_PTR(arg
);
39 static void match_call(struct expression
*expr
)
41 struct expression
*arg
;
47 FOR_EACH_PTR(expr
->args
, arg
) {
48 name
= get_macro_name(arg
->pos
);
49 if (!name
|| strncmp(name
, "GFP_", 4) != 0)
51 if (strcmp(name
, "GFP_KERNEL") != 0)
53 sm_msg("warn: use '%s' here instead of %s?", my_flags
, name
);
54 } END_FOR_EACH_PTR(arg
);
57 void check_not_passing_gfp(int id
)
59 if (option_project
!= PROJ_KERNEL
)
64 add_function_data((unsigned long *)&my_flags
);
66 add_hook(&match_function_definition
, FUNC_DEF_HOOK
);
67 add_hook(&match_call
, FUNCTION_CALL_HOOK
);