2 * sparse/check_dev_queue_xmit.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * According to an email on lkml you are not allowed to reuse the skb
12 * passed to dev_queue_xmit()
17 #include "smatch_slist.h"
23 static void ok_to_use(struct sm_state
*sm
)
25 set_state(my_id
, sm
->name
, sm
->sym
, &undefined
);
28 static int valid_use(void)
30 struct expression
*tmp
;
34 FOR_EACH_PTR_REVERSE(big_expression_stack
, tmp
) {
37 if (tmp
->type
== EXPR_PREOP
&& tmp
->op
== '(')
39 if (tmp
->op
== '.' && !dot_ops
++)
41 // if (tmp->type == EXPR_POSTOP)
43 if (tmp
->type
== EXPR_CALL
&& sym_name_is("kfree_skb", tmp
->fn
))
46 } END_FOR_EACH_PTR_REVERSE(tmp
);
50 /* match symbol is expensive. only turn it on after we match the xmit function */
51 static int match_symbol_active
;
52 static void match_symbol(struct expression
*expr
)
57 sm
= get_sm_state_expr(my_id
, expr
);
58 if (!sm
|| !slist_has_state(sm
->possible
, &do_not_use
))
62 name
= get_variable_from_expr(expr
, NULL
);
63 sm_msg("error: '%s' was already used up by dev_queue_xmit()", name
);
67 static void match_kfree_skb(const char *fn
, struct expression
*expr
, void *param
)
69 struct expression
*arg
;
71 arg
= get_argument_from_call_expr(expr
->args
, 0);
74 delete_state_expr(my_id
, arg
);
77 static void match_xmit(const char *fn
, struct expression
*expr
, void *param
)
79 struct expression
*arg
;
81 arg
= get_argument_from_call_expr(expr
->args
, PTR_INT(param
));
84 set_state_expr(my_id
, arg
, &do_not_use
);
85 if (!match_symbol_active
++) {
86 add_hook(&match_symbol
, SYM_HOOK
);
87 add_function_hook("kfree_skb", &match_kfree_skb
, NULL
);
91 static void register_funcs_from_file(void)
97 token
= get_tokens_file("kernel.dev_queue_xmit");
100 if (token_type(token
) != TOKEN_STREAMBEGIN
)
103 while (token_type(token
) != TOKEN_STREAMEND
) {
104 if (token_type(token
) != TOKEN_IDENT
)
106 func
= show_ident(token
->ident
);
108 if (token_type(token
) != TOKEN_NUMBER
)
110 arg
= atoi(token
->number
);
111 add_function_hook(func
, &match_xmit
, INT_PTR(arg
));
117 void check_dev_queue_xmit(int id
)
119 if (option_project
!= PROJ_KERNEL
|| !option_spammy
)
122 add_modification_hook(my_id
, ok_to_use
);
123 register_funcs_from_file();