2 * sparse/check_err_ptr.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * Functions should never return both NULL and ERR_PTR().
15 #include "smatch_slist.h"
19 static int err_ptr
= 0;
20 static int returns_null
= 0;
22 static void match_err_ptr(struct expression
*expr
)
24 expr
= strip_expr(expr
);
27 if (expr
->type
!= EXPR_CALL
)
30 if (expr
->fn
->type
!= EXPR_SYMBOL
|| !expr
->fn
->symbol
)
32 if (!strcmp(expr
->fn
->symbol
->ident
->name
, "ERR_PTR"))
36 extern int check_assigned_expr_id
;
37 static void match_return(struct expression
*ret_value
)
39 struct state_list
*slist
;
42 match_err_ptr(ret_value
);
43 slist
= get_possible_states_expr(check_assigned_expr_id
, ret_value
);
44 FOR_EACH_PTR(slist
, tmp
) {
45 if (tmp
->state
== &undefined
|| tmp
->state
== &merged
)
47 match_err_ptr((struct expression
*)tmp
->state
->data
);
48 } END_FOR_EACH_PTR(tmp
);
50 if (get_implied_value(ret_value
) == 0)
54 static void match_end_func(struct symbol
*sym
)
56 if (returns_null
&& err_ptr
)
57 sm_msg("warn: returns both null and ERR_PTR.");
59 sm_msg("info: returns_err_ptr");
64 void check_err_ptr(int id
)
70 add_hook(&match_return
, RETURN_HOOK
);
71 add_hook(&match_end_func
, END_FUNC_HOOK
);