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
22 static int in_function(const char *fn
)
24 char *cur_func
= get_function();
28 if (!strcmp(cur_func
, fn
))
33 static void match_free(const char *fn
, struct expression
*expr
, void *data
)
35 struct expression
*arg_expr
;
39 arg_expr
= get_argument_from_call_expr(expr
->args
, 0);
40 type
= get_pointer_type(arg_expr
);
41 if (!type
|| !type
->ident
)
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"))
51 if (in_function("alloc_netdev_mqs"))
53 sm_msg("error: use free_netdev() here instead of kfree(%s)", name
);
59 void check_type(int id
)
62 if (option_project
== PROJ_KERNEL
)
63 add_function_hook("kfree", &match_free
, NULL
);