2 * smatch/check_expects_err_ptr.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
13 static struct symbol
*func_sym
;
18 static void set_ok(const char *name
, struct symbol
*sym
, struct expression
*expr
, void *unused
)
20 set_state(my_id
, name
, sym
, &ok
);
23 static void match_function_def(struct symbol
*sym
)
28 FOR_EACH_PTR(func_sym
->ctype
.base_type
->arguments
, arg
) {
32 set_state(my_id
, arg
->ident
->name
, arg
, &argument
);
33 } END_FOR_EACH_PTR(arg
);
36 static int get_arg_num(struct expression
*expr
)
38 struct smatch_state
*state
;
40 struct symbol
*this_arg
;
43 expr
= strip_expr(expr
);
44 if (expr
->type
!= EXPR_SYMBOL
)
46 this_arg
= expr
->symbol
;
48 state
= get_state_expr(my_id
, expr
);
49 if (!state
|| state
!= &argument
)
53 FOR_EACH_PTR(func_sym
->ctype
.base_type
->arguments
, arg
) {
57 } END_FOR_EACH_PTR(arg
);
62 static void match_is_err(const char *fn
, struct expression
*expr
, void *unused
)
64 struct expression
*arg
;
67 arg
= get_argument_from_call_expr(expr
->args
, 0);
68 arg_num
= get_arg_num(arg
);
71 sm_msg("info: expects ERR_PTR %d", arg_num
);
74 void check_expects_err_ptr(int id
)
76 if (option_project
!= PROJ_KERNEL
)
82 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
83 set_default_modification_hook(my_id
, &set_ok
);
84 add_function_hook("IS_ERR", &match_is_err
, NULL
);