-
Notifications
You must be signed in to change notification settings - Fork 14
/
check_err_ptr_deref.c
81 lines (69 loc) · 1.87 KB
/
check_err_ptr_deref.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright 2023 Linaro Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
*/
#include "smatch.h"
#include "smatch_extra.h"
static int my_id;
/* These functions do not necessarily need to be checked */
static const char *safe_fns[] = {
"exynos_drm_crtc_get_by_type",
"mdp5_crtc_get_mixer",
"mdp5_crtc_get_pipeline",
"mlx5_eswitch_get_vport",
"mtk_vdec_h264_get_ctrl_ptr",
"nand_get_sdr_timings",
"tc358746_get_format_by_code",
"to_caam_req",
"uverbs_attr_get",
"uverbs_attr_get_alloced_ptr",
"uverbs_attr_get_obj",
"uverbs_attr_get_uobject",
};
static bool from_safe_fn(struct expression *expr)
{
struct expression *prev;
int i;
prev = get_assigned_expr(expr);
if (!prev)
return false;
if (prev->type != EXPR_CALL)
return false;
for (i = 0; i < ARRAY_SIZE(safe_fns); i++) {
if (sym_name_is(safe_fns[i], prev->fn))
return true;
}
return false;
}
static void deref_hook(struct expression *expr)
{
char *name;
if (!possible_err_ptr(expr))
return;
if (from_safe_fn(expr))
return;
if (is_impossible_path())
return;
name = expr_to_str(expr);
sm_error("'%s' dereferencing possible ERR_PTR()", name);
free_string(name);
}
void check_err_ptr_deref(int id)
{
my_id = id;
if (option_project != PROJ_KERNEL)
return;
add_dereference_hook(deref_hook);
}