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 struct symbol
*this_func
;
20 static int err_ptr
= 0;
21 static int returns_null
= 0;
23 static void match_function_def(struct symbol
*sym
)
28 static void match_err_ptr(const char *fn
, struct expression
*expr
, void *info
)
30 struct expression
*arg
;
33 arg
= get_argument_from_call_expr(expr
->args
, 0);
34 value
= get_implied_value(arg
);
35 if (value
!= UNDEFINED
&& value
< -4095)
36 smatch_msg("error: the error code is too large for ERR_PTR");
38 smatch_msg("info: returns_err_ptr");
42 static void match_return(struct statement
*stmt
)
44 if (get_implied_value(stmt
->ret_value
) != 0)
47 smatch_msg("info: returns_null");
51 static void match_end_func(struct symbol
*sym
)
57 void check_err_ptr(int id
)
60 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
61 add_function_hook("ERR_PTR", &match_err_ptr
, NULL
);
62 add_hook(&match_return
, RETURN_HOOK
);
63 add_hook(&match_end_func
, END_FUNC_HOOK
);