db/fixup_kernel.sh: fix clear_user() handling
[smatch.git] / check_uninitialized_kobj.c
blob3c41af2308cab50cce79768580e44194f411c29a
1 /*
2 * Copyright (C) 2023 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 #include "smatch.h"
19 #include "smatch_slist.h"
20 #include "smatch_extra.h"
22 static int my_id;
24 static void match_kobject_function(struct expression *expr, const char *name,
25 struct symbol *sym, void *data)
27 struct sm_state *sm, *tmp;
29 if (db_incomplete())
30 return;
32 sm = get_sm_state(SMATCH_EXTRA, name, sym);
33 if (!sm)
34 return;
36 FOR_EACH_PTR(sm->possible, tmp) {
37 if (rl_max(estate_rl(tmp->state)).value == 0)
38 sm_warning("Calling kobject_put|get with state->initialized unset from line: %d",
39 tmp->line);
40 } END_FOR_EACH_PTR(tmp);
43 void check_uninitialized_kobj(int id)
45 my_id = id;
47 if (option_project != PROJ_KERNEL)
48 return;
50 add_function_param_key_hook("kobject_put", &match_kobject_function, 0,
51 "$->state_initialized", NULL);
52 add_function_param_key_hook("kobject_get", &match_kobject_function, 0,
53 "$->state_initialized", NULL);