db/fixup_kernel.sh: fix clear_user() handling
[smatch.git] / smatch_kernel_task_state.c
blob14de0cb477dd83e2254fdde048201f84793a44d9
1 /*
2 * Copyright 2023 Linaro Ltd.
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"
21 static int my_id;
23 STATE(not_running);
25 bool task_not_running(void)
27 if (has_possible_state(my_id, "task_state", NULL, &not_running))
28 return true;
29 return false;
32 static void state_change_hook(struct expression *expr, const char *str)
34 if (strcmp(str, "not_running") == 0)
35 set_state(my_id, "task_state", NULL, &not_running);
36 else
37 set_state(my_id, "task_state", NULL, &undefined);
40 static void called_not_running(const char *name, struct symbol *sym, char *key, char *value)
42 set_state(my_id, "task_state", NULL, &not_running);
45 static void match_call_info(struct expression *expr)
47 if (task_not_running())
48 sql_insert_caller_info(expr, TASK_NOT_RUNNING, -2, "", "");
51 void register_kernel_task_state(int id)
53 my_id = id;
55 if (option_project != PROJ_KERNEL)
56 return;
58 add_set_current_state_hook(state_change_hook);
59 select_caller_info_hook(&called_not_running, TASK_NOT_RUNNING);
60 add_hook(&match_call_info, FUNCTION_CALL_HOOK);