perf tools fixes for v5.16: 4th batch

- Fix segfaults in 'perf inject' related to usage of unopened files.
 
 - The return value of hashmap__new() should be checked using IS_ERR().
 
 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQR2GiIUctdOfX2qHhGyPKLppCJ+JwUCYb3upAAKCRCyPKLppCJ+
 J9Y3AP4uRzl8VAh3kc/ahe2bGyLCi8KRi4ciVx9Y3a2AzfS46QD/TzDWIAl3Yg68
 HMvMiWcof8mMTXgLIcvWKkNxPNeQJwM=
 =rZro
 -----END PGP SIGNATURE-----

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()
This commit is contained in:
Linus Torvalds 2021-12-18 11:53:14 -08:00
commit 0f03adcca7
2 changed files with 14 additions and 4 deletions

View File

@ -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);
@ -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);
@ -1078,7 +1082,8 @@ out_delete:
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;
}

View File

@ -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>
@ -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;