2 * Copyright (C) 2010 Dan Carpenter.
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
19 * According to an email on lkml you are not allowed to reuse the skb
20 * passed to dev_queue_xmit()
25 #include "smatch_slist.h"
31 static int valid_use(void)
33 struct expression
*tmp
;
37 FOR_EACH_PTR_REVERSE(big_expression_stack
, tmp
) {
40 if (tmp
->type
== EXPR_PREOP
&& tmp
->op
== '(')
42 if (tmp
->op
== '.' && !dot_ops
++)
44 // if (tmp->type == EXPR_POSTOP)
46 if (tmp
->type
== EXPR_CALL
&& sym_name_is("kfree_skb", tmp
->fn
))
49 } END_FOR_EACH_PTR_REVERSE(tmp
);
53 /* match symbol is expensive. only turn it on after we match the xmit function */
54 static int match_symbol_active
;
55 static void match_symbol(struct expression
*expr
)
60 sm
= get_sm_state_expr(my_id
, expr
);
61 if (!sm
|| !slist_has_state(sm
->possible
, &do_not_use
))
65 name
= expr_to_var(expr
);
66 sm_error("'%s' was already used up by dev_queue_xmit()", name
);
70 static void match_kfree_skb(const char *fn
, struct expression
*expr
, void *param
)
72 struct expression
*arg
;
74 arg
= get_argument_from_call_expr(expr
->args
, 0);
77 set_state_expr(my_id
, arg
, &undefined
);
80 static void match_xmit(const char *fn
, struct expression
*expr
, void *param
)
82 struct expression
*arg
;
84 arg
= get_argument_from_call_expr(expr
->args
, PTR_INT(param
));
87 set_state_expr(my_id
, arg
, &do_not_use
);
88 if (!match_symbol_active
++) {
89 add_hook(&match_symbol
, SYM_HOOK
);
90 add_function_hook("kfree_skb", &match_kfree_skb
, NULL
);
94 static void register_funcs_from_file(void)
100 token
= get_tokens_file("kernel.dev_queue_xmit");
103 if (token_type(token
) != TOKEN_STREAMBEGIN
)
106 while (token_type(token
) != TOKEN_STREAMEND
) {
107 if (token_type(token
) != TOKEN_IDENT
)
109 func
= show_ident(token
->ident
);
111 if (token_type(token
) != TOKEN_NUMBER
)
113 arg
= atoi(token
->number
);
114 add_function_hook(func
, &match_xmit
, INT_PTR(arg
));
120 void check_dev_queue_xmit(int id
)
122 if (option_project
!= PROJ_KERNEL
)
125 add_modification_hook(my_id
, &set_undefined
);
126 register_funcs_from_file();