aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2018-05-17 13:27:29 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-05-17 13:49:36 -0400
commit25a7d914274de38637c5199342eb90a297361386 (patch)
tree58d563fe50180ff95dd71b2be4081aa750348e05
parentc02cab228e44aacf161642b63779971f8e39993b (diff)
perf parse-events: Use get/put_events_file()
Instead of accessing the trace_events_path variable directly, that may not have been properly initialized wrt detecting where tracefs is mounted. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: https://lkml.kernel.org/n/tip-id7hzn1ydgkxbumeve5wapqz@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/tests/parse-events.c7
-rw-r--r--tools/perf/util/parse-events.c50
-rw-r--r--tools/perf/util/trace-event.c8
3 files changed, 43 insertions, 22 deletions
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 6829dd416a99..6d57d7082637 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1328,7 +1328,7 @@ static int count_tracepoints(void)
1328 TEST_ASSERT_VAL("Can't open events dir", events_dir); 1328 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1329 1329
1330 while ((events_ent = readdir(events_dir))) { 1330 while ((events_ent = readdir(events_dir))) {
1331 char sys_path[PATH_MAX]; 1331 char *sys_path;
1332 struct dirent *sys_ent; 1332 struct dirent *sys_ent;
1333 DIR *sys_dir; 1333 DIR *sys_dir;
1334 1334
@@ -1339,8 +1339,8 @@ static int count_tracepoints(void)
1339 || !strcmp(events_ent->d_name, "header_page")) 1339 || !strcmp(events_ent->d_name, "header_page"))
1340 continue; 1340 continue;
1341 1341
1342 scnprintf(sys_path, PATH_MAX, "%s/%s", 1342 sys_path = get_events_file(events_ent->d_name);
1343 tracing_events_path, events_ent->d_name); 1343 TEST_ASSERT_VAL("Can't get sys path", sys_path);
1344 1344
1345 sys_dir = opendir(sys_path); 1345 sys_dir = opendir(sys_path);
1346 TEST_ASSERT_VAL("Can't open sys dir", sys_dir); 1346 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
@@ -1356,6 +1356,7 @@ static int count_tracepoints(void)
1356 } 1356 }
1357 1357
1358 closedir(sys_dir); 1358 closedir(sys_dir);
1359 put_events_file(sys_path);
1359 } 1360 }
1360 1361
1361 closedir(events_dir); 1362 closedir(events_dir);
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index f9d5bbd63484..24668300b327 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -189,19 +189,19 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
189 int fd; 189 int fd;
190 u64 id; 190 u64 id;
191 char evt_path[MAXPATHLEN]; 191 char evt_path[MAXPATHLEN];
192 char dir_path[MAXPATHLEN]; 192 char *dir_path;
193 193
194 sys_dir = opendir(tracing_events_path); 194 sys_dir = opendir(tracing_events_path);
195 if (!sys_dir) 195 if (!sys_dir)
196 return NULL; 196 return NULL;
197 197
198 for_each_subsystem(sys_dir, sys_dirent) { 198 for_each_subsystem(sys_dir, sys_dirent) {
199 199 dir_path = get_events_file(sys_dirent->d_name);
200 snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, 200 if (!dir_path)
201 sys_dirent->d_name); 201 continue;
202 evt_dir = opendir(dir_path); 202 evt_dir = opendir(dir_path);
203 if (!evt_dir) 203 if (!evt_dir)
204 continue; 204 goto next;
205 205
206 for_each_event(dir_path, evt_dir, evt_dirent) { 206 for_each_event(dir_path, evt_dir, evt_dirent) {
207 207
@@ -217,6 +217,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
217 close(fd); 217 close(fd);
218 id = atoll(id_buf); 218 id = atoll(id_buf);
219 if (id == config) { 219 if (id == config) {
220 put_events_file(dir_path);
220 closedir(evt_dir); 221 closedir(evt_dir);
221 closedir(sys_dir); 222 closedir(sys_dir);
222 path = zalloc(sizeof(*path)); 223 path = zalloc(sizeof(*path));
@@ -241,6 +242,8 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
241 } 242 }
242 } 243 }
243 closedir(evt_dir); 244 closedir(evt_dir);
245next:
246 put_events_file(dir_path);
244 } 247 }
245 248
246 closedir(sys_dir); 249 closedir(sys_dir);
@@ -511,14 +514,19 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
511 struct parse_events_error *err, 514 struct parse_events_error *err,
512 struct list_head *head_config) 515 struct list_head *head_config)
513{ 516{
514 char evt_path[MAXPATHLEN]; 517 char *evt_path;
515 struct dirent *evt_ent; 518 struct dirent *evt_ent;
516 DIR *evt_dir; 519 DIR *evt_dir;
517 int ret = 0, found = 0; 520 int ret = 0, found = 0;
518 521
519 snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name); 522 evt_path = get_events_file(sys_name);
523 if (!evt_path) {
524 tracepoint_error(err, errno, sys_name, evt_name);
525 return -1;
526 }
520 evt_dir = opendir(evt_path); 527 evt_dir = opendir(evt_path);
521 if (!evt_dir) { 528 if (!evt_dir) {
529 put_events_file(evt_path);
522 tracepoint_error(err, errno, sys_name, evt_name); 530 tracepoint_error(err, errno, sys_name, evt_name);
523 return -1; 531 return -1;
524 } 532 }
@@ -544,6 +552,7 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
544 ret = -1; 552 ret = -1;
545 } 553 }
546 554
555 put_events_file(evt_path);
547 closedir(evt_dir); 556 closedir(evt_dir);
548 return ret; 557 return ret;
549} 558}
@@ -2091,7 +2100,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
2091 DIR *sys_dir, *evt_dir; 2100 DIR *sys_dir, *evt_dir;
2092 struct dirent *sys_dirent, *evt_dirent; 2101 struct dirent *sys_dirent, *evt_dirent;
2093 char evt_path[MAXPATHLEN]; 2102 char evt_path[MAXPATHLEN];
2094 char dir_path[MAXPATHLEN]; 2103 char *dir_path;
2095 char **evt_list = NULL; 2104 char **evt_list = NULL;
2096 unsigned int evt_i = 0, evt_num = 0; 2105 unsigned int evt_i = 0, evt_num = 0;
2097 bool evt_num_known = false; 2106 bool evt_num_known = false;
@@ -2112,11 +2121,12 @@ restart:
2112 !strglobmatch(sys_dirent->d_name, subsys_glob)) 2121 !strglobmatch(sys_dirent->d_name, subsys_glob))
2113 continue; 2122 continue;
2114 2123
2115 snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, 2124 dir_path = get_events_file(sys_dirent->d_name);
2116 sys_dirent->d_name); 2125 if (!dir_path)
2126 continue;
2117 evt_dir = opendir(dir_path); 2127 evt_dir = opendir(dir_path);
2118 if (!evt_dir) 2128 if (!evt_dir)
2119 continue; 2129 goto next;
2120 2130
2121 for_each_event(dir_path, evt_dir, evt_dirent) { 2131 for_each_event(dir_path, evt_dir, evt_dirent) {
2122 if (event_glob != NULL && 2132 if (event_glob != NULL &&
@@ -2132,11 +2142,15 @@ restart:
2132 sys_dirent->d_name, evt_dirent->d_name); 2142 sys_dirent->d_name, evt_dirent->d_name);
2133 2143
2134 evt_list[evt_i] = strdup(evt_path); 2144 evt_list[evt_i] = strdup(evt_path);
2135 if (evt_list[evt_i] == NULL) 2145 if (evt_list[evt_i] == NULL) {
2146 put_events_file(dir_path);
2136 goto out_close_evt_dir; 2147 goto out_close_evt_dir;
2148 }
2137 evt_i++; 2149 evt_i++;
2138 } 2150 }
2139 closedir(evt_dir); 2151 closedir(evt_dir);
2152next:
2153 put_events_file(dir_path);
2140 } 2154 }
2141 closedir(sys_dir); 2155 closedir(sys_dir);
2142 2156
@@ -2184,19 +2198,19 @@ int is_valid_tracepoint(const char *event_string)
2184 DIR *sys_dir, *evt_dir; 2198 DIR *sys_dir, *evt_dir;
2185 struct dirent *sys_dirent, *evt_dirent; 2199 struct dirent *sys_dirent, *evt_dirent;
2186 char evt_path[MAXPATHLEN]; 2200 char evt_path[MAXPATHLEN];
2187 char dir_path[MAXPATHLEN]; 2201 char *dir_path;
2188 2202
2189 sys_dir = opendir(tracing_events_path); 2203 sys_dir = opendir(tracing_events_path);
2190 if (!sys_dir) 2204 if (!sys_dir)
2191 return 0; 2205 return 0;
2192 2206
2193 for_each_subsystem(sys_dir, sys_dirent) { 2207 for_each_subsystem(sys_dir, sys_dirent) {
2194 2208 dir_path = get_events_file(sys_dirent->d_name);
2195 snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, 2209 if (!dir_path)
2196 sys_dirent->d_name); 2210 continue;
2197 evt_dir = opendir(dir_path); 2211 evt_dir = opendir(dir_path);
2198 if (!evt_dir) 2212 if (!evt_dir)
2199 continue; 2213 goto next;
2200 2214
2201 for_each_event(dir_path, evt_dir, evt_dirent) { 2215 for_each_event(dir_path, evt_dir, evt_dirent) {
2202 snprintf(evt_path, MAXPATHLEN, "%s:%s", 2216 snprintf(evt_path, MAXPATHLEN, "%s:%s",
@@ -2208,6 +2222,8 @@ int is_valid_tracepoint(const char *event_string)
2208 } 2222 }
2209 } 2223 }
2210 closedir(evt_dir); 2224 closedir(evt_dir);
2225next:
2226 put_events_file(dir_path);
2211 } 2227 }
2212 closedir(sys_dir); 2228 closedir(sys_dir);
2213 return 0; 2229 return 0;
diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
index 16a776371d03..1aa368603268 100644
--- a/tools/perf/util/trace-event.c
+++ b/tools/perf/util/trace-event.c
@@ -75,6 +75,7 @@ void trace_event__cleanup(struct trace_event *t)
75static struct event_format* 75static struct event_format*
76tp_format(const char *sys, const char *name) 76tp_format(const char *sys, const char *name)
77{ 77{
78 char *tp_dir = get_events_file(sys);
78 struct pevent *pevent = tevent.pevent; 79 struct pevent *pevent = tevent.pevent;
79 struct event_format *event = NULL; 80 struct event_format *event = NULL;
80 char path[PATH_MAX]; 81 char path[PATH_MAX];
@@ -82,8 +83,11 @@ tp_format(const char *sys, const char *name)
82 char *data; 83 char *data;
83 int err; 84 int err;
84 85
85 scnprintf(path, PATH_MAX, "%s/%s/%s/format", 86 if (!tp_dir)
86 tracing_events_path, sys, name); 87 return ERR_PTR(-errno);
88
89 scnprintf(path, PATH_MAX, "%s/%s/format", tp_dir, name);
90 put_events_file(tp_dir);
87 91
88 err = filename__read_str(path, &data, &size); 92 err = filename__read_str(path, &data, &size);
89 if (err) 93 if (err)