Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1660858

[PATCH v4 6/9] perf tools: Consolidate error path in __open_dso()

From Namhyung Kim <namhyung@kernel.org>
Newsgroups linux.kernel
Subject [PATCH v4 6/9] perf tools: Consolidate error path in __open_dso()
Date 2017-06-08 09:40 +0200
Message-ID <tQ0cX-1hd-53@gated-at.bofh.it> (permalink)
References <tQ0cV-1hd-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On failure, it should free the 'name', so clean up the error path using
goto.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/dso.c | 19 ++++++++-----------
 1 file 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)
 
 static int __open_dso(struct dso *dso, struct machine *machine)
 {
-	int fd;
+	int fd = -EINVAL;
 	char *root_dir = (char *)"";
 	char *name = malloc(PATH_MAX);
 
@@ -465,23 +465,19 @@ static int __open_dso(struct dso *dso, struct machine *machine)
 		root_dir = machine->root_dir;
 
 	if (dso__read_binary_type_filename(dso, dso->binary_type,
-					    root_dir, name, PATH_MAX)) {
-		free(name);
-		return -EINVAL;
-	}
+					    root_dir, name, PATH_MAX))
+		goto out;
 
-	if (!is_regular_file(name)) {
-		free(name);
-		return -EINVAL;
-	}
+	if (!is_regular_file(name))
+		goto out;
 
 	if (dso__needs_decompress(dso)) {
 		char newpath[KMOD_DECOMP_LEN];
 		size_t len = sizeof(newpath);
 
 		if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
-			free(name);
-			return -dso->load_errno;
+			fd = -dso->load_errno;
+			goto out;
 		}
 
 		strcpy(name, newpath);
@@ -492,6 +488,7 @@ static int __open_dso(struct dso *dso, struct machine *machine)
 	if (dso__needs_decompress(dso))
 		unlink(name);
 
+out:
 	free(name);
 	return fd;
 }
-- 
2.13.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCHSET 0/9] perf tools: Fix for compressed kernel modules (v4) Namhyung Kim <namhyung@kernel.org> - 2017-06-08 09:40 +0200
  [PATCH v4 3/9] perf tools: Introduce dso__decompress_kmodule_{fd,path} Namhyung Kim <namhyung@kernel.org> - 2017-06-08 09:40 +0200
    [tip:perf/urgent] perf tools: Introduce  dso__decompress_kmodule_{fd,path} tip-bot for Namhyung Kim <tipbot@zytor.com> - 2017-06-09 01:00 +0200
  [PATCH v4 7/9] perf test: Decompress kernel module before objdump Namhyung Kim <namhyung@kernel.org> - 2017-06-08 09:40 +0200
    Re: [PATCH v4 7/9] perf test: Decompress kernel module before objdump Adrian Hunter <adrian.hunter@intel.com> - 2017-06-08 09:50 +0200
    [tip:perf/urgent] perf tests: Decompress kernel module before  objdump tip-bot for Namhyung Kim <tipbot@zytor.com> - 2017-06-09 01:00 +0200
  [PATCH v4 9/9] perf symbols: Kill dso__build_id_is_kmod() Namhyung Kim <namhyung@kernel.org> - 2017-06-08 09:40 +0200
    [tip:perf/urgent] perf symbols: Kill dso__build_id_is_kmod() tip-bot for Namhyung Kim <tipbot@zytor.com> - 2017-06-09 01:00 +0200
  [PATCH v4 4/9] perf annotate: Use dso__decompress_kmodule_path() Namhyung Kim <namhyung@kernel.org> - 2017-06-08 09:40 +0200
    [tip:perf/urgent] perf annotate: Use dso__decompress_kmodule_path() tip-bot for Namhyung Kim <tipbot@zytor.com> - 2017-06-09 01:00 +0200
  [PATCH v4 6/9] perf tools: Consolidate error path in __open_dso() Namhyung Kim <namhyung@kernel.org> - 2017-06-08 09:40 +0200
    [tip:perf/urgent] perf tools: Consolidate error path in  __open_dso() tip-bot for Namhyung Kim <tipbot@zytor.com> - 2017-06-09 01:00 +0200
  [PATCH v4 8/9] perf symbols: Keep DSO->symtab_type after decompress Namhyung Kim <namhyung@kernel.org> - 2017-06-08 09:40 +0200
    [tip:perf/urgent] perf symbols: Keep DSO->symtab_type after  decompress tip-bot for Namhyung Kim <tipbot@zytor.com> - 2017-06-09 01:00 +0200
  Re: [PATCHSET 0/9] perf tools: Fix for compressed kernel modules (v4) Jiri Olsa <jolsa@redhat.com> - 2017-06-08 14:20 +0200

csiph-web