浏览代码

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>
Robert Richter 13 年之前
父节点
当前提交
f4d834367c
共有 3 个文件被更改,包括 9 次插入6 次删除
  1. 1 1
      tools/perf/util/evsel.h
  2. 7 4
      tools/perf/util/header.c
  3. 1 1
      tools/perf/util/header.h

+ 1 - 1
tools/perf/util/evsel.h

@@ -53,7 +53,7 @@ struct perf_evsel {
 	u64			*id;
 	u64			*id;
 	struct perf_counts	*counts;
 	struct perf_counts	*counts;
 	int			idx;
 	int			idx;
-	int			ids;
+	u32			ids;
 	struct hists		hists;
 	struct hists		hists;
 	char			*name;
 	char			*name;
 	struct event_format	*tp_format;
 	struct event_format	*tp_format;

+ 7 - 4
tools/perf/util/header.c

@@ -2240,7 +2240,7 @@ out_delete_evlist:
 }
 }
 
 
 int perf_event__synthesize_attr(struct perf_tool *tool,
 int perf_event__synthesize_attr(struct perf_tool *tool,
-				struct perf_event_attr *attr, u16 ids, u64 *id,
+				struct perf_event_attr *attr, u32 ids, u64 *id,
 				perf_event__handler_t process)
 				perf_event__handler_t process)
 {
 {
 	union perf_event *ev;
 	union perf_event *ev;
@@ -2261,9 +2261,12 @@ int perf_event__synthesize_attr(struct perf_tool *tool,
 	memcpy(ev->attr.id, id, ids * sizeof(u64));
 	memcpy(ev->attr.id, id, ids * sizeof(u64));
 
 
 	ev->attr.header.type = PERF_RECORD_HEADER_ATTR;
 	ev->attr.header.type = PERF_RECORD_HEADER_ATTR;
-	ev->attr.header.size = size;
+	ev->attr.header.size = (u16)size;
 
 
-	err = process(tool, ev, NULL, NULL);
+	if (ev->attr.header.size == size)
+		err = process(tool, ev, NULL, NULL);
+	else
+		err = -E2BIG;
 
 
 	free(ev);
 	free(ev);
 
 
@@ -2292,7 +2295,7 @@ int perf_event__synthesize_attrs(struct perf_tool *tool,
 int perf_event__process_attr(union perf_event *event,
 int perf_event__process_attr(union perf_event *event,
 			     struct perf_evlist **pevlist)
 			     struct perf_evlist **pevlist)
 {
 {
-	unsigned int i, ids, n_ids;
+	u32 i, ids, n_ids;
 	struct perf_evsel *evsel;
 	struct perf_evsel *evsel;
 	struct perf_evlist *evlist = *pevlist;
 	struct perf_evlist *evlist = *pevlist;
 
 

+ 1 - 1
tools/perf/util/header.h

@@ -99,7 +99,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
 int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir);
 int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir);
 
 
 int perf_event__synthesize_attr(struct perf_tool *tool,
 int perf_event__synthesize_attr(struct perf_tool *tool,
-				struct perf_event_attr *attr, u16 ids, u64 *id,
+				struct perf_event_attr *attr, u32 ids, u64 *id,
 				perf_event__handler_t process);
 				perf_event__handler_t process);
 int perf_event__synthesize_attrs(struct perf_tool *tool,
 int perf_event__synthesize_attrs(struct perf_tool *tool,
 				 struct perf_session *session,
 				 struct perf_session *session,