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 void ok_to_use(struct sm_state
*sm
, struct expression
*mod_expr
)
33 set_state(my_id
, sm
->name
, sm
->sym
, &undefined
);
36 static int valid_use(void)
38 struct expression
*tmp
;
42 FOR_EACH_PTR_REVERSE(big_expression_stack
, tmp
) {
45 if (tmp
->type
== EXPR_PREOP
&& tmp
->op
== '(')
47 if (tmp
->op
== '.' && !dot_ops
++)
49 // if (tmp->type == EXPR_POSTOP)
51 if (tmp
->type
== EXPR_CALL
&& sym_name_is("kfree_skb", tmp
->fn
))
54 } END_FOR_EACH_PTR_REVERSE(tmp
);
58 /* match symbol is expensive. only turn it on after we match the xmit function */
59 static int match_symbol_active
;
60 static void match_symbol(struct expression
*expr
)
65 sm
= get_sm_state_expr(my_id
, expr
);
66 if (!sm
|| !slist_has_state(sm
->possible
, &do_not_use
))
70 name
= expr_to_var(expr
);
71 sm_error("'%s' was already used up by dev_queue_xmit()", name
);
75 static void match_kfree_skb(const char *fn
, struct expression
*expr
, void *param
)
77 struct expression
*arg
;
79 arg
= get_argument_from_call_expr(expr
->args
, 0);
82 set_state_expr(my_id
, arg
, &undefined
);
85 static void match_xmit(const char *fn
, struct expression
*expr
, void *param
)
87 struct expression
*arg
;
89 arg
= get_argument_from_call_expr(expr
->args
, PTR_INT(param
));
92 set_state_expr(my_id
, arg
, &do_not_use
);
93 if (!match_symbol_active
++) {
94 add_hook(&match_symbol
, SYM_HOOK
);
95 add_function_hook("kfree_skb", &match_kfree_skb
, NULL
);
99 static void register_funcs_from_file(void)
105 token
= get_tokens_file("kernel.dev_queue_xmit");
108 if (token_type(token
) != TOKEN_STREAMBEGIN
)
111 while (token_type(token
) != TOKEN_STREAMEND
) {
112 if (token_type(token
) != TOKEN_IDENT
)
114 func
= show_ident(token
->ident
);
116 if (token_type(token
) != TOKEN_NUMBER
)
118 arg
= atoi(token
->number
);
119 add_function_hook(func
, &match_xmit
, INT_PTR(arg
));
125 void check_dev_queue_xmit(int id
)
127 if (option_project
!= PROJ_KERNEL
)
130 add_modification_hook(my_id
, ok_to_use
);
131 register_funcs_from_file();