diff options
-rw-r--r-- | tools/perf/util/parse-events.c | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 13ab4b842d49..87c424de79ee 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -165,33 +165,31 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) | |||
165 | DIR *sys_dir, *evt_dir; | 165 | DIR *sys_dir, *evt_dir; |
166 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | 166 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
167 | char id_buf[4]; | 167 | char id_buf[4]; |
168 | int sys_dir_fd, fd; | 168 | int fd; |
169 | u64 id; | 169 | u64 id; |
170 | char evt_path[MAXPATHLEN]; | 170 | char evt_path[MAXPATHLEN]; |
171 | char dir_path[MAXPATHLEN]; | ||
171 | 172 | ||
172 | if (valid_debugfs_mount(debugfs_path)) | 173 | if (valid_debugfs_mount(debugfs_path)) |
173 | return NULL; | 174 | return NULL; |
174 | 175 | ||
175 | sys_dir = opendir(debugfs_path); | 176 | sys_dir = opendir(debugfs_path); |
176 | if (!sys_dir) | 177 | if (!sys_dir) |
177 | goto cleanup; | 178 | return NULL; |
178 | sys_dir_fd = dirfd(sys_dir); | ||
179 | 179 | ||
180 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { | 180 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
181 | int dfd = openat(sys_dir_fd, sys_dirent.d_name, | 181 | |
182 | O_RDONLY|O_DIRECTORY), evt_dir_fd; | 182 | snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, |
183 | if (dfd == -1) | 183 | sys_dirent.d_name); |
184 | continue; | 184 | evt_dir = opendir(dir_path); |
185 | evt_dir = fdopendir(dfd); | 185 | if (!evt_dir) |
186 | if (!evt_dir) { | ||
187 | close(dfd); | ||
188 | continue; | 186 | continue; |
189 | } | 187 | |
190 | evt_dir_fd = dirfd(evt_dir); | ||
191 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { | 188 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
192 | snprintf(evt_path, MAXPATHLEN, "%s/id", | 189 | |
190 | snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, | ||
193 | evt_dirent.d_name); | 191 | evt_dirent.d_name); |
194 | fd = openat(evt_dir_fd, evt_path, O_RDONLY); | 192 | fd = open(evt_path, O_RDONLY); |
195 | if (fd < 0) | 193 | if (fd < 0) |
196 | continue; | 194 | continue; |
197 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { | 195 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { |
@@ -225,7 +223,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) | |||
225 | closedir(evt_dir); | 223 | closedir(evt_dir); |
226 | } | 224 | } |
227 | 225 | ||
228 | cleanup: | ||
229 | closedir(sys_dir); | 226 | closedir(sys_dir); |
230 | return NULL; | 227 | return NULL; |
231 | } | 228 | } |
@@ -761,28 +758,24 @@ static void print_tracepoint_events(void) | |||
761 | { | 758 | { |
762 | DIR *sys_dir, *evt_dir; | 759 | DIR *sys_dir, *evt_dir; |
763 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | 760 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
764 | int sys_dir_fd; | ||
765 | char evt_path[MAXPATHLEN]; | 761 | char evt_path[MAXPATHLEN]; |
762 | char dir_path[MAXPATHLEN]; | ||
766 | 763 | ||
767 | if (valid_debugfs_mount(debugfs_path)) | 764 | if (valid_debugfs_mount(debugfs_path)) |
768 | return; | 765 | return; |
769 | 766 | ||
770 | sys_dir = opendir(debugfs_path); | 767 | sys_dir = opendir(debugfs_path); |
771 | if (!sys_dir) | 768 | if (!sys_dir) |
772 | goto cleanup; | 769 | return; |
773 | sys_dir_fd = dirfd(sys_dir); | ||
774 | 770 | ||
775 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { | 771 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
776 | int dfd = openat(sys_dir_fd, sys_dirent.d_name, | 772 | |
777 | O_RDONLY|O_DIRECTORY), evt_dir_fd; | 773 | snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, |
778 | if (dfd == -1) | 774 | sys_dirent.d_name); |
779 | continue; | 775 | evt_dir = opendir(dir_path); |
780 | evt_dir = fdopendir(dfd); | 776 | if (!evt_dir) |
781 | if (!evt_dir) { | ||
782 | close(dfd); | ||
783 | continue; | 777 | continue; |
784 | } | 778 | |
785 | evt_dir_fd = dirfd(evt_dir); | ||
786 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { | 779 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
787 | snprintf(evt_path, MAXPATHLEN, "%s:%s", | 780 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
788 | sys_dirent.d_name, evt_dirent.d_name); | 781 | sys_dirent.d_name, evt_dirent.d_name); |
@@ -791,8 +784,6 @@ static void print_tracepoint_events(void) | |||
791 | } | 784 | } |
792 | closedir(evt_dir); | 785 | closedir(evt_dir); |
793 | } | 786 | } |
794 | |||
795 | cleanup: | ||
796 | closedir(sys_dir); | 787 | closedir(sys_dir); |
797 | } | 788 | } |
798 | 789 | ||