Commit 0f03adcc authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'perf-tools-fixes-for-v5.16-2021-12-18' of...

Merge tag 'perf-tools-fixes-for-v5.16-2021-12-18' of git://git.kernel.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()
parents 9eaa88c7 c271a55b
...@@ -755,12 +755,16 @@ static int parse_vm_time_correlation(const struct option *opt, const char *str, ...@@ -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; 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) static int __cmd_inject(struct perf_inject *inject)
{ {
int ret = -EINVAL; int ret = -EINVAL;
struct perf_session *session = inject->session; struct perf_session *session = inject->session;
struct perf_data *data_out = &inject->output; int fd = output_fd(inject);
int fd = inject->in_place_update ? -1 : perf_data__fd(data_out);
u64 output_data_offset; u64 output_data_offset;
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
...@@ -1015,7 +1019,7 @@ int cmd_inject(int argc, const char **argv) ...@@ -1015,7 +1019,7 @@ int cmd_inject(int argc, const char **argv)
} }
inject.session = __perf_session__new(&data, repipe, inject.session = __perf_session__new(&data, repipe,
perf_data__fd(&inject.output), output_fd(&inject),
&inject.tool); &inject.tool);
if (IS_ERR(inject.session)) { if (IS_ERR(inject.session)) {
ret = PTR_ERR(inject.session); ret = PTR_ERR(inject.session);
...@@ -1078,7 +1082,8 @@ int cmd_inject(int argc, const char **argv) ...@@ -1078,7 +1082,8 @@ int cmd_inject(int argc, const char **argv)
zstd_fini(&(inject.session->zstd_data)); zstd_fini(&(inject.session->zstd_data));
perf_session__delete(inject.session); perf_session__delete(inject.session);
out_close_output: 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); free(inject.itrace_synth_opts.vm_tm_corr_args);
return ret; return ret;
} }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "expr-bison.h" #include "expr-bison.h"
#include "expr-flex.h" #include "expr-flex.h"
#include "smt.h" #include "smt.h"
#include <linux/err.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/zalloc.h> #include <linux/zalloc.h>
#include <ctype.h> #include <ctype.h>
...@@ -299,6 +300,10 @@ struct expr_parse_ctx *expr__ctx_new(void) ...@@ -299,6 +300,10 @@ struct expr_parse_ctx *expr__ctx_new(void)
return NULL; return NULL;
ctx->ids = hashmap__new(key_hash, key_equal, NULL); ctx->ids = hashmap__new(key_hash, key_equal, NULL);
if (IS_ERR(ctx->ids)) {
free(ctx);
return NULL;
}
ctx->runtime = 0; ctx->runtime = 0;
return ctx; return ctx;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment