All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf header: Fix lock/unlock imbalances
@ 2019-04-08 17:33 Gustavo A. R. Silva
  2019-04-08 18:22 ` Song Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Gustavo A. R. Silva @ 2019-04-08 17:33 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Song Liu
  Cc: linux-kernel, Gustavo A. R. Silva

Fix lock/unlock imbalances by refactoring the code a bit and adding
calls to up_write() before return.

Addresses-Coverity-ID: 1444315 ("Missing unlock")
Addresses-Coverity-ID: 1444316 ("Missing unlock")
Fixes: a70a1123174a ("perf bpf: Save BTF information as headers to perf.data")
Fixes: 606f972b1361 ("perf bpf: Save bpf_prog_info information as headers to perf.data")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 tools/perf/util/header.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index b9e693825873..06028e0ee06a 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2606,6 +2606,7 @@ static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_unused)
 		perf_env__insert_bpf_prog_info(env, info_node);
 	}
 
+	up_write(&env->bpf_progs.lock);
 	return 0;
 out:
 	free(info_linear);
@@ -2623,7 +2624,9 @@ static int process_bpf_prog_info(struct feat_fd *ff __maybe_unused, void *data _
 static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
 {
 	struct perf_env *env = &ff->ph->env;
+	struct btf_node *node;
 	u32 count, i;
+	int err = -1;
 
 	if (ff->ph->needs_swap) {
 		pr_warning("interpreting btf from systems with endianity is not yet supported\n");
@@ -2636,31 +2639,33 @@ static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
 	down_write(&env->bpf_progs.lock);
 
 	for (i = 0; i < count; ++i) {
-		struct btf_node *node;
 		u32 id, data_size;
 
+		node = NULL;
 		if (do_read_u32(ff, &id))
-			return -1;
+			goto out;
 		if (do_read_u32(ff, &data_size))
-			return -1;
+			goto out;
 
 		node = malloc(sizeof(struct btf_node) + data_size);
 		if (!node)
-			return -1;
+			goto out;
 
 		node->id = id;
 		node->data_size = data_size;
 
-		if (__do_read(ff, node->data, data_size)) {
-			free(node);
-			return -1;
-		}
+		if (__do_read(ff, node->data, data_size))
+			goto out;
 
 		perf_env__insert_btf(env, node);
 	}
 
 	up_write(&env->bpf_progs.lock);
 	return 0;
+out:
+	up_write(&env->bpf_progs.lock);
+	free(node);
+	return err;
 }
 
 struct feature_ops {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-04-16 15:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-08 17:33 [PATCH] perf header: Fix lock/unlock imbalances Gustavo A. R. Silva
2019-04-08 18:22 ` Song Liu
2019-04-08 18:26   ` Gustavo A. R. Silva
2019-04-08 19:35     ` Arnaldo Carvalho de Melo
2019-04-08 19:52       ` Gustavo A. R. Silva
2019-04-08 20:00         ` Arnaldo Carvalho de Melo
2019-04-08 20:08           ` Gustavo A. R. Silva
2019-04-12 16:37 ` [tip:perf/urgent] perf header: Fix lock/unlock imbalances when processing BPF/BTF info tip-bot for Gustavo A. R. Silva
2019-04-16 15:28 ` tip-bot for Gustavo A. R. Silva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.