2 * sparse/check_err_ptr.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_slist.h"
15 static int err_ptr
= 0;
16 static int returns_null
= 0;
18 static void match_err_ptr(struct expression
*expr
)
20 expr
= strip_expr(expr
);
23 if (expr
->type
!= EXPR_CALL
)
26 if (expr
->fn
->type
!= EXPR_SYMBOL
|| !expr
->fn
->symbol
)
28 if (!strcmp(expr
->fn
->symbol
->ident
->name
, "ERR_PTR"))
32 extern int check_assigned_expr_id
;
33 static void match_return(struct expression
*ret_value
)
35 struct state_list
*slist
;
41 match_err_ptr(ret_value
);
42 slist
= get_possible_states_expr(check_assigned_expr_id
, ret_value
);
43 FOR_EACH_PTR(slist
, tmp
) {
44 if (tmp
->state
== &undefined
|| tmp
->state
== &merged
)
46 match_err_ptr((struct expression
*)tmp
->state
->data
);
47 } END_FOR_EACH_PTR(tmp
);
49 if (get_implied_value(ret_value
, &sval
)) {
55 static void match_end_func(struct symbol
*sym
)
60 sm_info("returns_err_ptr");
65 void check_err_ptr(int id
)
67 if (option_project
!= PROJ_KERNEL
)
73 add_hook(&match_return
, RETURN_HOOK
);
74 add_hook(&match_end_func
, END_FUNC_HOOK
);