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 <jo...@redhat.com>
Cc: Corey Ashford <cjash...@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweis...@gmail.com>
Cc: Ingo Molnar <mi...@elte.hu>
Cc: Namhyung Kim <namhy...@kernel.org>
Cc: Paul Mackerras <pau...@samba.org>
Cc: Peter Zijlstra <a.p.zijls...@chello.nl>
Cc: Arnaldo Carvalho de Melo <a...@redhat.com>
Cc: Andi Kleen <a...@linux.intel.com>
Cc: Stephane Eranian <eran...@google.com>
---
 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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to