]> Pileus Git - ~andy/linux/commitdiff
perf tools: Do proper comm override error handling
authorFrederic Weisbecker <fweisbec@gmail.com>
Tue, 14 Jan 2014 15:37:14 +0000 (16:37 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 16 Jan 2014 19:44:39 +0000 (16:44 -0300)
The comm overriding API ignores memory allocation failures by silently
keeping the previous and out of date comm.

As a result, the user may get buggy events without ever being notified
about the problem and its source.

Lets start to fix this by propagating the error from the API. Not all
callers may be doing proper error handling on comm set yet but this is
the first step toward it.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1389713836-13375-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/comm.c
tools/perf/util/comm.h
tools/perf/util/thread.c

index 67d1e404c0cb732d29394eebab3a2125035d3447..f9e777629e21cd1780fad2dc891f4c24d637787e 100644 (file)
@@ -94,19 +94,20 @@ struct comm *comm__new(const char *str, u64 timestamp)
        return comm;
 }
 
-void comm__override(struct comm *comm, const char *str, u64 timestamp)
+int comm__override(struct comm *comm, const char *str, u64 timestamp)
 {
-       struct comm_str *old = comm->comm_str;
+       struct comm_str *new, *old = comm->comm_str;
 
-       comm->comm_str = comm_str__findnew(str, &comm_str_root);
-       if (!comm->comm_str) {
-               comm->comm_str = old;
-               return;
-       }
+       new = comm_str__findnew(str, &comm_str_root);
+       if (!new)
+               return -ENOMEM;
 
-       comm->start = timestamp;
-       comm_str__get(comm->comm_str);
+       comm_str__get(new);
        comm_str__put(old);
+       comm->comm_str = new;
+       comm->start = timestamp;
+
+       return 0;
 }
 
 void comm__free(struct comm *comm)
index 7a86e5656710a76176a2b00eb8891d24ef117edd..fac5bd51befc4c4a2b6aafe5cd21220829334673 100644 (file)
@@ -16,6 +16,6 @@ struct comm {
 void comm__free(struct comm *comm);
 struct comm *comm__new(const char *str, u64 timestamp);
 const char *comm__str(const struct comm *comm);
-void comm__override(struct comm *comm, const char *str, u64 timestamp);
+int comm__override(struct comm *comm, const char *str, u64 timestamp);
 
 #endif  /* __PERF_COMM_H */
index e3948612543e9faabc62cdf8fd2c7cd364568c6a..0358882c89108723616c4eca0431fed0aa6be200 100644 (file)
@@ -66,10 +66,13 @@ struct comm *thread__comm(const struct thread *thread)
 int thread__set_comm(struct thread *thread, const char *str, u64 timestamp)
 {
        struct comm *new, *curr = thread__comm(thread);
+       int err;
 
        /* Override latest entry if it had no specific time coverage */
        if (!curr->start) {
-               comm__override(curr, str, timestamp);
+               err = comm__override(curr, str, timestamp);
+               if (err)
+                       return err;
        } else {
                new = comm__new(str, timestamp);
                if (!new)