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()
22 static void ok_to_use(const char *name
, struct symbol
*sym
, struct expression
*expr
, void *unused
)
24 delete_state(my_id
, name
, sym
);
27 static int valid_use(void)
29 struct expression
*tmp
;
33 FOR_EACH_PTR_REVERSE(big_expression_stack
, tmp
) {
36 if (tmp
->type
== EXPR_PREOP
&& tmp
->op
== '(')
38 if (tmp
->op
== '.' && !dot_ops
++)
40 // if (tmp->type == EXPR_POSTOP)
42 if (tmp
->type
== EXPR_CALL
&& sym_name_is("kfree_skb", tmp
->fn
))
45 } END_FOR_EACH_PTR_REVERSE(tmp
);
49 /* match symbol is expensive. only turn it on after we match the xmit function */
50 static int match_symbol_active
;
51 static void match_symbol(struct expression
*expr
)
56 sm
= get_sm_state_expr(my_id
, expr
);
61 name
= get_variable_from_expr(expr
, NULL
);
62 sm_msg("error: '%s' was already used up by dev_queue_xmit()", name
);
66 static void match_kfree_skb(const char *fn
, struct expression
*expr
, void *param
)
68 struct expression
*arg
;
70 arg
= get_argument_from_call_expr(expr
->args
, 0);
73 delete_state_expr(my_id
, arg
);
76 static void match_xmit(const char *fn
, struct expression
*expr
, void *param
)
78 struct expression
*arg
;
80 arg
= get_argument_from_call_expr(expr
->args
, PTR_INT(param
));
83 set_state_expr(my_id
, arg
, &do_not_use
);
84 if (!match_symbol_active
++) {
85 add_hook(&match_symbol
, SYM_HOOK
);
86 add_function_hook("kfree_skb", &match_kfree_skb
, NULL
);
90 static void register_funcs_from_file(void)
96 token
= get_tokens_file("kernel.dev_queue_xmit");
99 if (token_type(token
) != TOKEN_STREAMBEGIN
)
102 while (token_type(token
) != TOKEN_STREAMEND
) {
103 if (token_type(token
) != TOKEN_IDENT
)
105 func
= show_ident(token
->ident
);
107 if (token_type(token
) != TOKEN_NUMBER
)
109 arg
= atoi(token
->number
);
110 add_function_hook(func
, &match_xmit
, INT_PTR(arg
));
116 void check_dev_queue_xmit(int id
)
118 if (option_project
!= PROJ_KERNEL
|| !option_spammy
)
121 set_default_modification_hook(my_id
, ok_to_use
);
122 register_funcs_from_file();