sval: update smatch_helper.c
[smatch.git] / check_err_ptr.c
blob7c7dd32933e81ebb3c7835c364cca16a34d13ec1
1 /*
2 * sparse/check_err_ptr.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_slist.h"
13 static int my_id;
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);
21 if (!expr)
22 return;
23 if (expr->type != EXPR_CALL)
24 return;
26 if (expr->fn->type != EXPR_SYMBOL || !expr->fn->symbol)
27 return;
28 if (!strcmp(expr->fn->symbol->ident->name, "ERR_PTR"))
29 err_ptr = 1;
32 extern int check_assigned_expr_id;
33 static void match_return(struct expression *ret_value)
35 struct state_list *slist;
36 struct sm_state *tmp;
37 sval_t sval;
39 match_err_ptr(ret_value);
40 slist = get_possible_states_expr(check_assigned_expr_id, ret_value);
41 FOR_EACH_PTR(slist, tmp) {
42 if (tmp->state == &undefined || tmp->state == &merged)
43 continue;
44 match_err_ptr((struct expression *)tmp->state->data);
45 } END_FOR_EACH_PTR(tmp);
47 if (get_implied_value_sval(ret_value, &sval)) {
48 if (sval.value == 0)
49 returns_null = 1;
53 static void match_end_func(struct symbol *sym)
55 if (err_ptr)
56 sm_info("returns_err_ptr");
57 err_ptr = 0;
58 returns_null = 0;
61 void check_err_ptr(int id)
63 if (option_project != PROJ_KERNEL)
64 return;
65 if (!option_info)
66 return;
68 my_id = id;
69 add_hook(&match_return, RETURN_HOOK);
70 add_hook(&match_end_func, END_FUNC_HOOK);