db: caller info needs to record the -1 parameters
[smatch.git] / check_kernel.c
blob062a5dbbbf814683b1f1717ccfac24a3aa1d91cf
1 /*
2 * sparse/check_kernel.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
11 * This is kernel specific stuff for smatch_extra.
14 #include "smatch.h"
15 #include "smatch_extra.h"
17 static void match_param_nonnull(const char *fn, struct expression *call_expr,
18 struct expression *assign_expr, void *_param)
20 int param = PTR_INT(_param);
21 struct expression *arg;
22 struct smatch_state *pre_state;
23 struct smatch_state *true_state;
25 arg = get_argument_from_call_expr(call_expr->args, param);
26 pre_state = get_state_expr(SMATCH_EXTRA, arg);
27 true_state = add_filter(pre_state, 0);
28 set_extra_expr_nomod(arg, true_state);
31 static void match_container_of(const char *fn, struct expression *expr, void *unused)
33 set_extra_expr_mod(expr->left, alloc_extra_state_range(1, POINTER_MAX));
36 void check_kernel(int id)
38 if (option_project != PROJ_KERNEL)
39 return;
41 return_implies_state("IS_ERR_OR_NULL", 0, 0, &match_param_nonnull, (void *)0);
42 return_implies_state("tomoyo_memory_ok", 1, 1, &match_param_nonnull, (void *)0);
43 add_macro_assign_hook("container_of", &match_container_of, NULL);