Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/check_dma_mapping_error.c
+++ new/usr/src/tools/smatch/src/check_dma_mapping_error.c
1 1 /*
2 2 * Copyright (C) 2015 Oracle.
3 3 *
4 4 * This program is free software; you can redistribute it and/or
5 5 * modify it under the terms of the GNU General Public License
6 6 * as published by the Free Software Foundation; either version 2
7 7 * of the License, or (at your option) any later version.
8 8 *
9 9 * This program is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 * GNU General Public License for more details.
13 13 *
14 14 * You should have received a copy of the GNU General Public License
15 15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 16 */
17 17
18 18 #include "smatch.h"
19 19 #include "smatch_slist.h"
20 20 #include "smatch_extra.h"
21 21
22 22 static int my_id;
23 23
24 24 STATE(positive);
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
25 25 STATE(ok);
26 26
27 27 static void ok_to_use(struct sm_state *sm, struct expression *mod_expr)
28 28 {
29 29 if (sm->state != &ok)
30 30 set_state(my_id, sm->name, sm->sym, &ok);
31 31 }
32 32
33 33 static void match_assign(const char *fn, struct expression *expr, void *unused)
34 34 {
35 + struct range_list *rl;
36 +
37 + if (!get_implied_rl(expr->right, &rl))
38 + return;
39 + if (rl_max(rl).value != 1)
40 + return;
35 41 set_state_expr(my_id, expr->left, &positive);
36 42 }
37 43
38 44 static void match_condition(struct expression *expr)
39 45 {
40 46 if (!get_state_expr(my_id, expr))
41 47 return;
42 48 /* If the variable is zero that's ok */
43 49 set_true_false_states_expr(my_id, expr, NULL, &ok);
44 50 }
45 51
46 52 static void match_return(struct expression *ret_value)
47 53 {
48 54 struct smatch_state *state;
49 55 struct sm_state *sm;
50 56 sval_t min;
51 57
52 58 sm = get_sm_state_expr(my_id, ret_value);
53 59 if (!sm)
54 60 return;
55 61 if (!slist_has_state(sm->possible, &positive))
56 62 return;
57 63 state = get_state_expr(SMATCH_EXTRA, ret_value);
58 64 if (!state)
59 65 return;
60 66 if (!get_absolute_min(ret_value, &min))
61 67 return;
62 68 if (min.value == 0)
63 69 return;
64 70 sm_warning("dma_mapping_error() doesn't return an error code");
65 71 }
66 72
67 73 void check_dma_mapping_error(int id)
68 74 {
69 75 if (option_project != PROJ_KERNEL)
70 76 return;
71 77
72 78 my_id = id;
73 79 add_function_assign_hook("dma_mapping_error", &match_assign, NULL);
74 80 add_function_assign_hook("pci_dma_mapping_error", &match_assign, NULL);
75 81 add_hook(&match_condition, CONDITION_HOOK);
76 82 add_hook(&match_return, RETURN_HOOK);
77 83 add_modification_hook(my_id, &ok_to_use);
78 84 }
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX