diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2013-03-21 03:18:45 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-03-21 12:12:28 -0400 |
commit | 5a6fd27ad73fef0ed39a00236acbc3a17834672a (patch) | |
tree | 0dbe82d5625aca21ec96ad032e4375ba613b0e36 /tools/perf | |
parent | 454f8c7d26fa7e1545df4efca5d9ba929ccef1e8 (diff) |
perf tools: Get rid of malloc_or_die() in trace-event-info.c
Check return value of malloc and fail if NULL.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1363850332-25297-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/trace-event-info.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c index 81c673282ed4..91db6e8e4493 100644 --- a/tools/perf/util/trace-event-info.c +++ b/tools/perf/util/trace-event-info.c | |||
@@ -47,16 +47,6 @@ static const char *output_file = "trace.info"; | |||
47 | static int output_fd; | 47 | static int output_fd; |
48 | 48 | ||
49 | 49 | ||
50 | static void *malloc_or_die(unsigned int size) | ||
51 | { | ||
52 | void *data; | ||
53 | |||
54 | data = malloc(size); | ||
55 | if (!data) | ||
56 | die("malloc"); | ||
57 | return data; | ||
58 | } | ||
59 | |||
60 | static const char *find_debugfs(void) | 50 | static const char *find_debugfs(void) |
61 | { | 51 | { |
62 | const char *path = perf_debugfs_mount(NULL); | 52 | const char *path = perf_debugfs_mount(NULL); |
@@ -209,7 +199,7 @@ static bool name_in_tp_list(char *sys, struct tracepoint_path *tps) | |||
209 | return false; | 199 | return false; |
210 | } | 200 | } |
211 | 201 | ||
212 | static void copy_event_system(const char *sys, struct tracepoint_path *tps) | 202 | static int copy_event_system(const char *sys, struct tracepoint_path *tps) |
213 | { | 203 | { |
214 | struct dirent *dent; | 204 | struct dirent *dent; |
215 | struct stat st; | 205 | struct stat st; |
@@ -217,6 +207,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps) | |||
217 | DIR *dir; | 207 | DIR *dir; |
218 | int count = 0; | 208 | int count = 0; |
219 | int ret; | 209 | int ret; |
210 | int err; | ||
220 | 211 | ||
221 | dir = opendir(sys); | 212 | dir = opendir(sys); |
222 | if (!dir) | 213 | if (!dir) |
@@ -228,7 +219,11 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps) | |||
228 | strcmp(dent->d_name, "..") == 0 || | 219 | strcmp(dent->d_name, "..") == 0 || |
229 | !name_in_tp_list(dent->d_name, tps)) | 220 | !name_in_tp_list(dent->d_name, tps)) |
230 | continue; | 221 | continue; |
231 | format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10); | 222 | format = malloc(strlen(sys) + strlen(dent->d_name) + 10); |
223 | if (!format) { | ||
224 | err = -ENOMEM; | ||
225 | goto out; | ||
226 | } | ||
232 | sprintf(format, "%s/%s/format", sys, dent->d_name); | 227 | sprintf(format, "%s/%s/format", sys, dent->d_name); |
233 | ret = stat(format, &st); | 228 | ret = stat(format, &st); |
234 | free(format); | 229 | free(format); |
@@ -246,16 +241,22 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps) | |||
246 | strcmp(dent->d_name, "..") == 0 || | 241 | strcmp(dent->d_name, "..") == 0 || |
247 | !name_in_tp_list(dent->d_name, tps)) | 242 | !name_in_tp_list(dent->d_name, tps)) |
248 | continue; | 243 | continue; |
249 | format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10); | 244 | format = malloc(strlen(sys) + strlen(dent->d_name) + 10); |
245 | if (!format) { | ||
246 | err = -ENOMEM; | ||
247 | goto out; | ||
248 | } | ||
250 | sprintf(format, "%s/%s/format", sys, dent->d_name); | 249 | sprintf(format, "%s/%s/format", sys, dent->d_name); |
251 | ret = stat(format, &st); | 250 | ret = stat(format, &st); |
252 | 251 | ||
253 | if (ret >= 0) | 252 | if (ret >= 0) |
254 | record_file(format, 8); | 253 | record_file(format, 8); |
255 | |||
256 | free(format); | 254 | free(format); |
257 | } | 255 | } |
256 | err = 0; | ||
257 | out: | ||
258 | closedir(dir); | 258 | closedir(dir); |
259 | return err; | ||
259 | } | 260 | } |
260 | 261 | ||
261 | static void read_ftrace_files(struct tracepoint_path *tps) | 262 | static void read_ftrace_files(struct tracepoint_path *tps) |
@@ -282,7 +283,7 @@ static bool system_in_tp_list(char *sys, struct tracepoint_path *tps) | |||
282 | return false; | 283 | return false; |
283 | } | 284 | } |
284 | 285 | ||
285 | static void read_event_files(struct tracepoint_path *tps) | 286 | static int read_event_files(struct tracepoint_path *tps) |
286 | { | 287 | { |
287 | struct dirent *dent; | 288 | struct dirent *dent; |
288 | struct stat st; | 289 | struct stat st; |
@@ -291,6 +292,7 @@ static void read_event_files(struct tracepoint_path *tps) | |||
291 | DIR *dir; | 292 | DIR *dir; |
292 | int count = 0; | 293 | int count = 0; |
293 | int ret; | 294 | int ret; |
295 | int err; | ||
294 | 296 | ||
295 | path = get_tracing_file("events"); | 297 | path = get_tracing_file("events"); |
296 | if (!path) | 298 | if (!path) |
@@ -320,7 +322,11 @@ static void read_event_files(struct tracepoint_path *tps) | |||
320 | strcmp(dent->d_name, "ftrace") == 0 || | 322 | strcmp(dent->d_name, "ftrace") == 0 || |
321 | !system_in_tp_list(dent->d_name, tps)) | 323 | !system_in_tp_list(dent->d_name, tps)) |
322 | continue; | 324 | continue; |
323 | sys = malloc_or_die(strlen(path) + strlen(dent->d_name) + 2); | 325 | sys = malloc(strlen(path) + strlen(dent->d_name) + 2); |
326 | if (!sys) { | ||
327 | err = -ENOMEM; | ||
328 | goto out; | ||
329 | } | ||
324 | sprintf(sys, "%s/%s", path, dent->d_name); | 330 | sprintf(sys, "%s/%s", path, dent->d_name); |
325 | ret = stat(sys, &st); | 331 | ret = stat(sys, &st); |
326 | if (ret >= 0) { | 332 | if (ret >= 0) { |
@@ -329,9 +335,12 @@ static void read_event_files(struct tracepoint_path *tps) | |||
329 | } | 335 | } |
330 | free(sys); | 336 | free(sys); |
331 | } | 337 | } |
332 | 338 | err = 0; | |
339 | out: | ||
333 | closedir(dir); | 340 | closedir(dir); |
334 | put_tracing_file(path); | 341 | put_tracing_file(path); |
342 | |||
343 | return err; | ||
335 | } | 344 | } |
336 | 345 | ||
337 | static void read_proc_kallsyms(void) | 346 | static void read_proc_kallsyms(void) |
@@ -463,7 +472,10 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs, | |||
463 | if (!tps) | 472 | if (!tps) |
464 | return NULL; | 473 | return NULL; |
465 | 474 | ||
466 | tdata = malloc_or_die(sizeof(*tdata)); | 475 | tdata = malloc(sizeof(*tdata)); |
476 | if (!tdata) | ||
477 | return NULL; | ||
478 | |||
467 | tdata->temp = temp; | 479 | tdata->temp = temp; |
468 | tdata->size = 0; | 480 | tdata->size = 0; |
469 | 481 | ||