fill_db_caller_info: calculate function_id correctly
[smatch.git] / check_type.c
blobb26ef36fd9f1a97ad0d6a65a8f12e391b2a1d17f
1 /*
2 * sparse/check_type.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_free(const char *fn, struct expression *expr, void *data)
16 struct expression *arg_expr;
17 char *name;
18 struct symbol *type;
20 arg_expr = get_argument_from_call_expr(expr->args, 0);
21 type = get_type(arg_expr);
23 if (!type || (type->type != SYM_PTR && type->type != SYM_ARRAY))
24 return;
25 type = get_base_type(type);
27 if (!type || !type->ident)
28 return;
30 name = get_variable_from_expr_complex(arg_expr, NULL);
32 if (!strcmp("sk_buff", type->ident->name))
33 sm_msg("error: use kfree_skb() here instead of kfree(%s)", name);
34 else if (!strcmp("net_device", type->ident->name))
35 sm_msg("error: use free_netdev() here instead of kfree(%s)", name);
37 free_string(name);
40 void check_type(int id)
42 my_id = id;
43 if (option_project == PROJ_KERNEL)
44 add_function_hook("kfree", &match_free, NULL);