diff options
author | Namhyung Kim <namhyung@kernel.org> | 2017-06-08 03:31:06 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-06-08 14:39:13 -0400 |
commit | 8ba29adf9a7cdff3c7283d5fc0dcf5e777d3b40f (patch) | |
tree | 8dc403b78aff477be820b9222d103ac1f37d0249 /tools | |
parent | 1d6b3c9ba756a5134fd7ad1959acac776d17404b (diff) |
perf tools: Consolidate error path in __open_dso()
On failure, it should free the 'name', so clean up the error path using
goto.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: kernel-team@lge.com
Link: http://lkml.kernel.org/r/20170608073109.30699-7-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/dso.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index c63525d845c5..4e7ab611377a 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c | |||
@@ -454,7 +454,7 @@ static int do_open(char *name) | |||
454 | 454 | ||
455 | static int __open_dso(struct dso *dso, struct machine *machine) | 455 | static int __open_dso(struct dso *dso, struct machine *machine) |
456 | { | 456 | { |
457 | int fd; | 457 | int fd = -EINVAL; |
458 | char *root_dir = (char *)""; | 458 | char *root_dir = (char *)""; |
459 | char *name = malloc(PATH_MAX); | 459 | char *name = malloc(PATH_MAX); |
460 | 460 | ||
@@ -465,23 +465,19 @@ static int __open_dso(struct dso *dso, struct machine *machine) | |||
465 | root_dir = machine->root_dir; | 465 | root_dir = machine->root_dir; |
466 | 466 | ||
467 | if (dso__read_binary_type_filename(dso, dso->binary_type, | 467 | if (dso__read_binary_type_filename(dso, dso->binary_type, |
468 | root_dir, name, PATH_MAX)) { | 468 | root_dir, name, PATH_MAX)) |
469 | free(name); | 469 | goto out; |
470 | return -EINVAL; | ||
471 | } | ||
472 | 470 | ||
473 | if (!is_regular_file(name)) { | 471 | if (!is_regular_file(name)) |
474 | free(name); | 472 | goto out; |
475 | return -EINVAL; | ||
476 | } | ||
477 | 473 | ||
478 | if (dso__needs_decompress(dso)) { | 474 | if (dso__needs_decompress(dso)) { |
479 | char newpath[KMOD_DECOMP_LEN]; | 475 | char newpath[KMOD_DECOMP_LEN]; |
480 | size_t len = sizeof(newpath); | 476 | size_t len = sizeof(newpath); |
481 | 477 | ||
482 | if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) { | 478 | if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) { |
483 | free(name); | 479 | fd = -dso->load_errno; |
484 | return -dso->load_errno; | 480 | goto out; |
485 | } | 481 | } |
486 | 482 | ||
487 | strcpy(name, newpath); | 483 | strcpy(name, newpath); |
@@ -492,6 +488,7 @@ static int __open_dso(struct dso *dso, struct machine *machine) | |||
492 | if (dso__needs_decompress(dso)) | 488 | if (dso__needs_decompress(dso)) |
493 | unlink(name); | 489 | unlink(name); |
494 | 490 | ||
491 | out: | ||
495 | free(name); | 492 | free(name); |
496 | return fd; | 493 | return fd; |
497 | } | 494 | } |