Skip to content

Commit

Permalink
Merge tag 'perf-tools-fixes-for-v5.16-2021-12-18' of git://git.kernel…
Browse files Browse the repository at this point in the history
….org/pub/scm/linux/kernel/git/acme/linux

Pull perf tools fixes from Arnaldo Carvalho de Melo:

 - Fix segfaults in 'perf inject' related to usage of unopened files

 - The return value of hashmap__new() should be checked using IS_ERR()

* tag 'perf-tools-fixes-for-v5.16-2021-12-18' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux:
  perf inject: Fix segfault due to perf_data__fd() without open
  perf inject: Fix segfault due to close without open
  perf expr: Fix missing check for return value of hashmap__new()
  • Loading branch information
Linus Torvalds committed Dec 18, 2021
2 parents 9eaa88c + c271a55 commit 0f03adc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,16 @@ static int parse_vm_time_correlation(const struct option *opt, const char *str,
return inject->itrace_synth_opts.vm_tm_corr_args ? 0 : -ENOMEM;
}

static int output_fd(struct perf_inject *inject)
{
return inject->in_place_update ? -1 : perf_data__fd(&inject->output);
}

static int __cmd_inject(struct perf_inject *inject)
{
int ret = -EINVAL;
struct perf_session *session = inject->session;
struct perf_data *data_out = &inject->output;
int fd = inject->in_place_update ? -1 : perf_data__fd(data_out);
int fd = output_fd(inject);
u64 output_data_offset;

signal(SIGINT, sig_handler);
Expand Down Expand Up @@ -1015,7 +1019,7 @@ int cmd_inject(int argc, const char **argv)
}

inject.session = __perf_session__new(&data, repipe,
perf_data__fd(&inject.output),
output_fd(&inject),
&inject.tool);
if (IS_ERR(inject.session)) {
ret = PTR_ERR(inject.session);
Expand Down Expand Up @@ -1078,7 +1082,8 @@ int cmd_inject(int argc, const char **argv)
zstd_fini(&(inject.session->zstd_data));
perf_session__delete(inject.session);
out_close_output:
perf_data__close(&inject.output);
if (!inject.in_place_update)
perf_data__close(&inject.output);
free(inject.itrace_synth_opts.vm_tm_corr_args);
return ret;
}
5 changes: 5 additions & 0 deletions tools/perf/util/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "expr-bison.h"
#include "expr-flex.h"
#include "smt.h"
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/zalloc.h>
#include <ctype.h>
Expand Down Expand Up @@ -299,6 +300,10 @@ struct expr_parse_ctx *expr__ctx_new(void)
return NULL;

ctx->ids = hashmap__new(key_hash, key_equal, NULL);
if (IS_ERR(ctx->ids)) {
free(ctx);
return NULL;
}
ctx->runtime = 0;

return ctx;
Expand Down

0 comments on commit 0f03adc

Please sign in to comment.