2 * Copyright 2023 Linaro Ltd.
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
19 #include "smatch_extra.h"
23 /* These functions do not necessarily need to be checked */
24 static const char *safe_fns
[] = {
25 "exynos_drm_crtc_get_by_type",
26 "mdp5_crtc_get_mixer",
27 "mdp5_crtc_get_pipeline",
28 "mlx5_eswitch_get_vport",
29 "mtk_vdec_h264_get_ctrl_ptr",
30 "nand_get_sdr_timings",
31 "tc358746_get_format_by_code",
34 "uverbs_attr_get_alloced_ptr",
35 "uverbs_attr_get_obj",
36 "uverbs_attr_get_uobject",
39 static bool from_safe_fn(struct expression
*expr
)
41 struct expression
*prev
;
44 prev
= get_assigned_expr(expr
);
47 if (prev
->type
!= EXPR_CALL
)
50 for (i
= 0; i
< ARRAY_SIZE(safe_fns
); i
++) {
51 if (sym_name_is(safe_fns
[i
], prev
->fn
))
57 static void deref_hook(struct expression
*expr
)
61 if (!possible_err_ptr(expr
))
63 if (from_safe_fn(expr
))
66 name
= expr_to_str(expr
);
67 sm_error("'%s' dereferencing possible ERR_PTR()", name
);
71 void check_err_ptr_deref(int id
)
75 if (option_project
!= PROJ_KERNEL
)
78 add_dereference_hook(deref_hook
);