Skip to content

Commit

Permalink
perf probe: Check return value of strlist__add() for -ENOMEM
Browse files Browse the repository at this point in the history
strlist__add() may fail with -ENOMEM. Check it and give debugging hint
in advance.

Signed-off-by: He Zhe <zhe.he@windriver.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lore.kernel.org/lkml/1582727404-180095-1-git-send-email-zhe.he@windriver.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
He Zhe authored and Arnaldo Carvalho de Melo committed Feb 27, 2020
1 parent b0aaf4c commit bd862b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
6 changes: 4 additions & 2 deletions tools/perf/builtin-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ static int perf_del_probe_events(struct strfilter *filter)
ret = probe_file__del_strlist(kfd, klist);
if (ret < 0)
goto error;
}
} else if (ret == -ENOMEM)
goto error;

ret2 = probe_file__get_events(ufd, filter, ulist);
if (ret2 == 0) {
Expand All @@ -459,7 +460,8 @@ static int perf_del_probe_events(struct strfilter *filter)
ret2 = probe_file__del_strlist(ufd, ulist);
if (ret2 < 0)
goto error;
}
} else if (ret2 == -ENOMEM)
goto error;

if (ret == -ENOENT && ret2 == -ENOENT)
pr_warning("\"%s\" does not hit any event.\n", str);
Expand Down
28 changes: 24 additions & 4 deletions tools/perf/util/probe-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,15 @@ int probe_file__get_events(int fd, struct strfilter *filter,
p = strchr(ent->s, ':');
if ((p && strfilter__compare(filter, p + 1)) ||
strfilter__compare(filter, ent->s)) {
strlist__add(plist, ent->s);
ret = strlist__add(plist, ent->s);
if (ret == -ENOMEM) {
pr_err("strlist__add failed with -ENOMEM\n");
goto out;
}
ret = 0;
}
}
out:
strlist__delete(namelist);

return ret;
Expand Down Expand Up @@ -511,7 +516,11 @@ static int probe_cache__load(struct probe_cache *pcache)
ret = -EINVAL;
goto out;
}
strlist__add(entry->tevlist, buf);
ret = strlist__add(entry->tevlist, buf);
if (ret == -ENOMEM) {
pr_err("strlist__add failed with -ENOMEM\n");
goto out;
}
}
}
out:
Expand Down Expand Up @@ -672,7 +681,12 @@ int probe_cache__add_entry(struct probe_cache *pcache,
command = synthesize_probe_trace_command(&tevs[i]);
if (!command)
goto out_err;
strlist__add(entry->tevlist, command);
ret = strlist__add(entry->tevlist, command);
if (ret == -ENOMEM) {
pr_err("strlist__add failed with -ENOMEM\n");
goto out_err;
}

free(command);
}
list_add_tail(&entry->node, &pcache->entries);
Expand Down Expand Up @@ -853,9 +867,15 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
break;
}

strlist__add(entry->tevlist, buf);
ret = strlist__add(entry->tevlist, buf);

free(buf);
entry = NULL;

if (ret == -ENOMEM) {
pr_err("strlist__add failed with -ENOMEM\n");
break;
}
}
if (entry) {
list_del_init(&entry->node);
Expand Down

0 comments on commit bd862b1

Please sign in to comment.