signed: unsigned variables are allowed to do math with negatives
[smatch.git] / check_le16.c
blobbe6b0a2d1de634ce1809eb90deb861f5d240c087
1 /*
2 * smatch/check_le16.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_no_le16_param(const char *fn, struct expression *expr, void *param)
16 struct expression *arg;
17 char *macro_name;
18 char *name;
20 arg = get_argument_from_call_expr(expr->args, (int)param);
21 if (!arg)
22 return;
23 macro_name = get_macro_name(&arg->pos);
24 if (!macro_name || strcmp(macro_name, "cpu_to_le16"))
25 return;
27 arg = strip_expr(arg);
28 name = get_variable_from_expr_complex(arg, NULL);
29 sm_msg("warn: don't need to call cpu_to_le16() for '%s'", name);
30 free_string(name);
33 static void register_funcs_from_file(void)
35 struct token *token;
36 const char *func;
37 int arg;
39 token = get_tokens_file("kernel.no_le16");
40 if (!token)
41 return;
42 if (token_type(token) != TOKEN_STREAMBEGIN)
43 return;
44 token = token->next;
45 while (token_type(token) != TOKEN_STREAMEND) {
46 if (token_type(token) != TOKEN_IDENT)
47 return;
48 func = show_ident(token->ident);
49 token = token->next;
50 if (token_type(token) != TOKEN_NUMBER)
51 return;
52 arg = atoi(token->number);
53 add_function_hook(func, &match_no_le16_param, INT_PTR(arg));
54 token = token->next;
56 clear_token_alloc();
59 void check_le16(int id)
61 if (option_project != PROJ_KERNEL)
62 return;
63 my_id = id;
64 register_funcs_from_file();