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
22 static int is_probably_ok(struct expression
*expr
)
24 expr
= strip_expr(expr
);
26 if (expr
->type
== EXPR_BINOP
)
28 if (expr
->type
== EXPR_SIZEOF
)
34 static void verify_size_expr(struct expression
*expr
)
36 if (expr
->type
!= EXPR_BINOP
)
40 if (is_probably_ok(expr
->left
))
42 if (is_probably_ok(expr
->right
))
44 sm_warning("consider using resource_size() here");
47 static void handle_assigned_expr(struct expression
*expr
)
49 expr
= get_assigned_expr(expr
);
52 verify_size_expr(expr
);
55 static void match_resource(const char *fn
, struct expression
*expr
, void *_arg_no
)
57 struct expression
*arg_expr
;
58 int arg_no
= PTR_INT(_arg_no
);
60 arg_expr
= get_argument_from_call_expr(expr
->args
, arg_no
);
61 arg_expr
= strip_expr(arg_expr
);
65 if (arg_expr
->type
== EXPR_SYMBOL
) {
66 handle_assigned_expr(arg_expr
);
69 verify_size_expr(arg_expr
);
72 void check_resource_size(int id
)
76 if (option_project
!= PROJ_KERNEL
)
79 add_function_hook("ioremap_nocache", &match_resource
, (void *)1);
80 add_function_hook("ioremap", &match_resource
, (void *)1);
81 add_function_hook("__request_region", &match_resource
, (void *)2);
82 add_function_hook("__release_region", &match_resource
, (void *)2);
83 add_function_hook("__devm_request_region", &match_resource
, (void *)3);
84 add_function_hook("__devm_release_region", &match_resource
, (void *)3);