generisize.pl: filter some more stuff
[smatch.git] / check_type.c
blob31f5eed34b0e9630061207ce8b1a4456a9d9f699
1 /*
2 * Copyright (C) 2009 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
18 #include "smatch.h"
20 static int my_id;
22 static int in_function(const char *fn)
24 char *cur_func = get_function();
26 if (!cur_func)
27 return 0;
28 if (!strcmp(cur_func, fn))
29 return 1;
30 return 0;
33 static void match_free(const char *fn, struct expression *expr, void *data)
35 struct expression *arg_expr;
36 char *name;
37 struct symbol *type;
39 arg_expr = get_argument_from_call_expr(expr->args, 0);
40 type = get_pointer_type(arg_expr);
41 if (!type || !type->ident)
42 return;
44 name = expr_to_str(arg_expr);
46 if (!strcmp("sk_buff", type->ident->name)) {
47 sm_msg("error: use kfree_skb() here instead of kfree(%s)", name);
48 } else if (!strcmp("net_device", type->ident->name)) {
49 if (in_function("alloc_netdev"))
50 return;
51 if (in_function("alloc_netdev_mqs"))
52 return;
53 sm_msg("error: use free_netdev() here instead of kfree(%s)", name);
56 free_string(name);
59 void check_type(int id)
61 my_id = id;
62 if (option_project == PROJ_KERNEL)
63 add_function_hook("kfree", &match_free, NULL);