[PATCH 2/8] perf tools: Change perf_pmu__new_alias function interface

From: Jiri Olsa
Date: Sat Jan 26 2013 - 15:05:22 EST


Changing perf_pmu__new_alias interface not to work directly with
FILE object, so it can be reused by other code paths coming in
shortly.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
---
tools/perf/util/pmu.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 4c6f9c4..f7852e9 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -95,23 +95,17 @@ static int pmu_format(char *name, struct list_head *format)
return 0;
}

-static int perf_pmu__new_alias(struct list_head *list, char *name, FILE *file)
+static int perf_pmu__new_alias(struct list_head *list, char *name, char *data)
{
struct perf_pmu_alias *alias;
- char buf[256];
int ret;

- ret = fread(buf, 1, sizeof(buf), file);
- if (ret == 0)
- return -EINVAL;
- buf[ret] = 0;
-
alias = malloc(sizeof(*alias));
if (!alias)
return -ENOMEM;

INIT_LIST_HEAD(&alias->terms);
- ret = parse_events_terms(&alias->terms, buf);
+ ret = parse_events_terms(&alias->terms, data);
if (ret) {
free(alias);
return ret;
@@ -137,7 +131,7 @@ static int pmu_aliases_parse(char *dir, struct list_head *head)
return -EINVAL;

while (!ret && (evt_ent = readdir(event_dir))) {
- char path[PATH_MAX];
+ char path[PATH_MAX], buf[256];
char *name = evt_ent->d_name;
FILE *file;

@@ -150,7 +144,16 @@ static int pmu_aliases_parse(char *dir, struct list_head *head)
file = fopen(path, "r");
if (!file)
break;
- ret = perf_pmu__new_alias(head, name, file);
+
+ ret = fread(buf, 1, sizeof(buf), file);
+ if (ret == 0) {
+ ret = -EINVAL;
+ break;
+ }
+
+ buf[ret] = 0;
+
+ ret = perf_pmu__new_alias(head, name, buf);
fclose(file);
}

--
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/