free_strict: print the line number where the pointer was freed
[smatch.git] / check_not_passing_gfp.c
blobeec1fb1a7ba42ccba646edbbfd7d083574a605ed
1 /*
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
18 #include "smatch.h"
19 #include "smatch_slist.h"
21 static int my_id;
23 static const char *my_flags;
25 static void match_function_definition(struct symbol *sym)
27 struct symbol *arg;
28 char *type_str;
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)
33 continue;
34 my_flags = arg->ident->name;
35 return;
36 } END_FOR_EACH_PTR(arg);
39 static void match_call(struct expression *expr)
41 struct expression *arg;
42 char *name;
44 if (!my_flags)
45 return;
47 FOR_EACH_PTR(expr->args, arg) {
48 name = get_macro_name(arg->pos);
49 if (!name || strncmp(name, "GFP_", 4) != 0)
50 continue;
51 if (strcmp(name, "GFP_KERNEL") != 0)
52 continue;
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)
60 return;
62 my_id = id;
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);