Skip to content

Commit 1f9f4f4

Browse files
committed
tracing/probes: Fix to add NULL check for BTF APIs
Since find_btf_func_param() abd btf_type_by_id() can return NULL, the caller must check the return value correctly. Link: https://lore.kernel.org/all/169024903951.395371.11361556840733470934.stgit@devnote2/ Fixes: b576e09 ("tracing/probes: Support function parameters if BTF is available") Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 6eaae19 commit 1f9f4f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

kernel/trace/trace_probe.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,12 @@ static const struct btf_type *find_btf_func_proto(const char *funcname)
386386

387387
/* Get BTF_KIND_FUNC type */
388388
t = btf_type_by_id(btf, id);
389-
if (!btf_type_is_func(t))
389+
if (!t || !btf_type_is_func(t))
390390
return ERR_PTR(-ENOENT);
391391

392392
/* The type of BTF_KIND_FUNC is BTF_KIND_FUNC_PROTO */
393393
t = btf_type_by_id(btf, t->type);
394-
if (!btf_type_is_func_proto(t))
394+
if (!t || !btf_type_is_func_proto(t))
395395
return ERR_PTR(-ENOENT);
396396

397397
return t;
@@ -443,7 +443,7 @@ static int parse_btf_arg(const char *varname, struct fetch_insn *code,
443443
if (!ctx->params) {
444444
params = find_btf_func_param(ctx->funcname, &ctx->nr_params,
445445
ctx->flags & TPARG_FL_TPOINT);
446-
if (IS_ERR(params)) {
446+
if (IS_ERR_OR_NULL(params)) {
447447
trace_probe_log_err(ctx->offset, NO_BTF_ENTRY);
448448
return PTR_ERR(params);
449449
}
@@ -1273,7 +1273,7 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[],
12731273

12741274
params = find_btf_func_param(ctx->funcname, &nr_params,
12751275
ctx->flags & TPARG_FL_TPOINT);
1276-
if (IS_ERR(params)) {
1276+
if (IS_ERR_OR_NULL(params)) {
12771277
if (args_idx != -1) {
12781278
/* $arg* requires BTF info */
12791279
trace_probe_log_err(0, NOSUP_BTFARG);

0 commit comments

Comments
 (0)