4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
14 static int in_function(const char *fn
)
16 char *cur_func
= get_function();
20 if (!strcmp(cur_func
, fn
))
25 static void match_free(const char *fn
, struct expression
*expr
, void *data
)
27 struct expression
*arg_expr
;
31 arg_expr
= get_argument_from_call_expr(expr
->args
, 0);
32 type
= get_pointer_type(arg_expr
);
33 if (!type
|| !type
->ident
)
36 name
= expr_to_str(arg_expr
);
38 if (!strcmp("sk_buff", type
->ident
->name
)) {
39 sm_msg("error: use kfree_skb() here instead of kfree(%s)", name
);
40 } else if (!strcmp("net_device", type
->ident
->name
)) {
41 if (in_function("alloc_netdev"))
43 if (in_function("alloc_netdev_mqs"))
45 sm_msg("error: use free_netdev() here instead of kfree(%s)", name
);
51 void check_type(int id
)
54 if (option_project
== PROJ_KERNEL
)
55 add_function_hook("kfree", &match_free
, NULL
);