2 * Copyright (C) 2010 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 is_kmalloc_call(struct expression
*expr
)
24 if (expr
->type
!= EXPR_CALL
)
26 if (expr
->fn
->type
!= EXPR_SYMBOL
)
28 if (!strcmp(expr
->fn
->symbol_name
->name
, "kmalloc"))
30 if (!strcmp(expr
->fn
->symbol_name
->name
, "kzalloc"))
35 static void match_condition(struct expression
*expr
)
38 struct expression
*right
;
41 macro
= get_macro_name(expr
->pos
);
42 if (!macro
|| strcmp(macro
, "BUG_ON") != 0)
44 right
= get_assigned_expr(expr
);
45 if (!right
|| !is_kmalloc_call(right
))
48 name
= expr_to_var(expr
);
49 sm_warning("bug on allocation failure '%s'", name
);
53 void check_kmalloc_to_bugon(int id
)
55 if (option_project
!= PROJ_KERNEL
)
60 add_hook(&match_condition
, CONDITION_HOOK
);