lkml.org 
[lkml]   [2017]   [Apr]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 6/7] perf tool: protect empty evlists
Date
A common pattern in in pipe-mode bugs is accessing an empty evlist.
Return NULL to make it easier to catch this problems.

Signed-off-by: David Carrillo-Cisneros <davidcc@google.com>
---
tools/perf/util/evlist.h | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 39942995f537..ba4788462325 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -257,11 +257,15 @@ void perf_evlist__splice_list_tail(struct perf_evlist *evlist,

static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
{
+ if (list_empty(&evlist->entries))
+ return NULL;
return list_entry(evlist->entries.next, struct perf_evsel, node);
}

static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
{
+ if (list_empty(&evlist->entries))
+ return NULL;
return list_entry(evlist->entries.prev, struct perf_evsel, node);
}

--
2.12.2.715.g7642488e1d-goog
\
 
 \ /
  Last update: 2017-04-10 22:16    [W:0.147 / U:22.880 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site