db/vim_db: don't complain when the file is not found
[smatch.git] / check_dma_mapping_error.c
blob10662db37312e6cb0a34290ddb77c5bf7bd70eff
1 /*
2 * Copyright (C) 2015 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 STATE(positive);
25 STATE(ok);
27 static void ok_to_use(struct sm_state *sm, struct expression *mod_expr)
29 if (sm->state != &ok)
30 set_state(my_id, sm->name, sm->sym, &ok);
33 static void match_assign(const char *fn, struct expression *expr, void *unused)
35 struct range_list *rl;
37 if (!get_implied_rl(expr->right, &rl))
38 return;
39 if (rl_max(rl).value != 1)
40 return;
41 set_state_expr(my_id, expr->left, &positive);
44 static void match_condition(struct expression *expr)
46 if (!get_state_expr(my_id, expr))
47 return;
48 /* If the variable is zero that's ok */
49 set_true_false_states_expr(my_id, expr, NULL, &ok);
52 static void match_return(struct expression *ret_value)
54 struct smatch_state *state;
55 struct sm_state *sm;
56 sval_t min;
58 sm = get_sm_state_expr(my_id, ret_value);
59 if (!sm)
60 return;
61 if (!slist_has_state(sm->possible, &positive))
62 return;
63 state = get_state_expr(SMATCH_EXTRA, ret_value);
64 if (!state)
65 return;
66 if (!get_absolute_min(ret_value, &min))
67 return;
68 if (min.value == 0)
69 return;
70 sm_warning("dma_mapping_error() doesn't return an error code");
73 void check_dma_mapping_error(int id)
75 if (option_project != PROJ_KERNEL)
76 return;
78 my_id = id;
79 add_function_assign_hook("dma_mapping_error", &match_assign, NULL);
80 add_function_assign_hook("pci_dma_mapping_error", &match_assign, NULL);
81 add_hook(&match_condition, CONDITION_HOOK);
82 add_hook(&match_return, RETURN_HOOK);
83 add_modification_hook(my_id, &ok_to_use);