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 extern int check_assigned_expr_id
;
24 static int is_kmalloc_call(struct expression
*expr
)
26 if (expr
->type
!= EXPR_CALL
)
28 if (expr
->fn
->type
!= EXPR_SYMBOL
)
30 if (!strcmp(expr
->fn
->symbol_name
->name
, "kmalloc"))
32 if (!strcmp(expr
->fn
->symbol_name
->name
, "kzalloc"))
37 static void match_condition(struct expression
*expr
)
40 struct smatch_state
*state
;
41 struct expression
*right
;
44 macro
= get_macro_name(expr
->pos
);
45 if (!macro
|| strcmp(macro
, "BUG_ON") != 0)
47 state
= get_state_expr(check_assigned_expr_id
, expr
);
48 if (!state
|| !state
->data
)
50 right
= (struct expression
*)state
->data
;
51 if (!is_kmalloc_call(right
))
54 name
= expr_to_var(expr
);
55 sm_msg("warn: bug on allocation failure '%s'", name
);
59 void check_kmalloc_to_bugon(int id
)
61 if (option_project
!= PROJ_KERNEL
)
66 add_hook(&match_condition
, CONDITION_HOOK
);