aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Richter <robert.richter@amd.com>2012-08-16 15:10:17 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-08-17 11:38:07 -0400
commitf4d834367cda98eee3769638da6ad687607c74e6 (patch)
tree09330b6187bdfab61645324f4fd0788a13bf79c7
parent0985a94891c73740dea1e2697f9d598a4a7810ab (diff)
perf tools: Fix type for evsel->ids and add size check for ids
Use same type for ids everywhere. In case of writing to perf.data the size is u32. In pipe mode it is limited to header.size (less than u16). Adding a size check here. Size overflow due to casting shouldn't actually happen in practice, but during development this may cause type missmatch warninngs/errors, unifying types avoids this. Signed-off-by: Robert Richter <robert.richter@amd.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1345144224-27280-2-git-send-email-robert.richter@amd.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/evsel.h2
-rw-r--r--tools/perf/util/header.c11
-rw-r--r--tools/perf/util/header.h2
3 files changed, 9 insertions, 6 deletions
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 65f39fdf821a..94f6ba16747f 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -53,7 +53,7 @@ struct perf_evsel {
53 u64 *id; 53 u64 *id;
54 struct perf_counts *counts; 54 struct perf_counts *counts;
55 int idx; 55 int idx;
56 int ids; 56 u32 ids;
57 struct hists hists; 57 struct hists hists;
58 char *name; 58 char *name;
59 struct event_format *tp_format; 59 struct event_format *tp_format;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 77832b807eff..471b0c42db3f 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2240,7 +2240,7 @@ out_delete_evlist:
2240} 2240}
2241 2241
2242int perf_event__synthesize_attr(struct perf_tool *tool, 2242int perf_event__synthesize_attr(struct perf_tool *tool,
2243 struct perf_event_attr *attr, u16 ids, u64 *id, 2243 struct perf_event_attr *attr, u32 ids, u64 *id,
2244 perf_event__handler_t process) 2244 perf_event__handler_t process)
2245{ 2245{
2246 union perf_event *ev; 2246 union perf_event *ev;
@@ -2261,9 +2261,12 @@ int perf_event__synthesize_attr(struct perf_tool *tool,
2261 memcpy(ev->attr.id, id, ids * sizeof(u64)); 2261 memcpy(ev->attr.id, id, ids * sizeof(u64));
2262 2262
2263 ev->attr.header.type = PERF_RECORD_HEADER_ATTR; 2263 ev->attr.header.type = PERF_RECORD_HEADER_ATTR;
2264 ev->attr.header.size = size; 2264 ev->attr.header.size = (u16)size;
2265 2265
2266 err = process(tool, ev, NULL, NULL); 2266 if (ev->attr.header.size == size)
2267 err = process(tool, ev, NULL, NULL);
2268 else
2269 err = -E2BIG;
2267 2270
2268 free(ev); 2271 free(ev);
2269 2272
@@ -2292,7 +2295,7 @@ int perf_event__synthesize_attrs(struct perf_tool *tool,
2292int perf_event__process_attr(union perf_event *event, 2295int perf_event__process_attr(union perf_event *event,
2293 struct perf_evlist **pevlist) 2296 struct perf_evlist **pevlist)
2294{ 2297{
2295 unsigned int i, ids, n_ids; 2298 u32 i, ids, n_ids;
2296 struct perf_evsel *evsel; 2299 struct perf_evsel *evsel;
2297 struct perf_evlist *evlist = *pevlist; 2300 struct perf_evlist *evlist = *pevlist;
2298 2301
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 2d42b3e1826f..24962e707e5b 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -99,7 +99,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
99int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir); 99int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir);
100 100
101int perf_event__synthesize_attr(struct perf_tool *tool, 101int perf_event__synthesize_attr(struct perf_tool *tool,
102 struct perf_event_attr *attr, u16 ids, u64 *id, 102 struct perf_event_attr *attr, u32 ids, u64 *id,
103 perf_event__handler_t process); 103 perf_event__handler_t process);
104int perf_event__synthesize_attrs(struct perf_tool *tool, 104int perf_event__synthesize_attrs(struct perf_tool *tool,
105 struct perf_session *session, 105 struct perf_session *session,