提交 d400a68d 编写于 作者: A Andy Shevchenko 提交者: Arnaldo Carvalho de Melo

perf tools: Convert open coded equivalents to asprintf()

The following snippet
	V = malloc(S);
	if (!V) { }
	sprintf(V, ...)

Can be easily changed to a one line:

	if (asprintf(&V, ...) < 0) { }
Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Link: http://lkml.kernel.org/r/1404474229-15272-1-git-send-email-andriy.shevchenko@linux.intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 f8d9ccde
...@@ -191,12 +191,10 @@ static int copy_event_system(const char *sys, struct tracepoint_path *tps) ...@@ -191,12 +191,10 @@ static int copy_event_system(const char *sys, struct tracepoint_path *tps)
strcmp(dent->d_name, "..") == 0 || strcmp(dent->d_name, "..") == 0 ||
!name_in_tp_list(dent->d_name, tps)) !name_in_tp_list(dent->d_name, tps))
continue; continue;
format = malloc(strlen(sys) + strlen(dent->d_name) + 10); if (asprintf(&format, "%s/%s/format", sys, dent->d_name) < 0) {
if (!format) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
sprintf(format, "%s/%s/format", sys, dent->d_name);
ret = stat(format, &st); ret = stat(format, &st);
free(format); free(format);
if (ret < 0) if (ret < 0)
...@@ -217,12 +215,10 @@ static int copy_event_system(const char *sys, struct tracepoint_path *tps) ...@@ -217,12 +215,10 @@ static int copy_event_system(const char *sys, struct tracepoint_path *tps)
strcmp(dent->d_name, "..") == 0 || strcmp(dent->d_name, "..") == 0 ||
!name_in_tp_list(dent->d_name, tps)) !name_in_tp_list(dent->d_name, tps))
continue; continue;
format = malloc(strlen(sys) + strlen(dent->d_name) + 10); if (asprintf(&format, "%s/%s/format", sys, dent->d_name) < 0) {
if (!format) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
sprintf(format, "%s/%s/format", sys, dent->d_name);
ret = stat(format, &st); ret = stat(format, &st);
if (ret >= 0) { if (ret >= 0) {
...@@ -317,12 +313,10 @@ static int record_event_files(struct tracepoint_path *tps) ...@@ -317,12 +313,10 @@ static int record_event_files(struct tracepoint_path *tps)
strcmp(dent->d_name, "ftrace") == 0 || strcmp(dent->d_name, "ftrace") == 0 ||
!system_in_tp_list(dent->d_name, tps)) !system_in_tp_list(dent->d_name, tps))
continue; continue;
sys = malloc(strlen(path) + strlen(dent->d_name) + 2); if (asprintf(&sys, "%s/%s", path, dent->d_name) < 0) {
if (!sys) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
sprintf(sys, "%s/%s", path, dent->d_name);
ret = stat(sys, &st); ret = stat(sys, &st);
if (ret >= 0) { if (ret >= 0) {
ssize_t size = strlen(dent->d_name) + 1; ssize_t size = strlen(dent->d_name) + 1;
......
...@@ -333,12 +333,9 @@ const char *find_tracing_dir(void) ...@@ -333,12 +333,9 @@ const char *find_tracing_dir(void)
if (!debugfs) if (!debugfs)
return NULL; return NULL;
tracing = malloc(strlen(debugfs) + 9); if (asprintf(&tracing, "%s/tracing", debugfs) < 0)
if (!tracing)
return NULL; return NULL;
sprintf(tracing, "%s/tracing", debugfs);
tracing_found = 1; tracing_found = 1;
return tracing; return tracing;
} }
...@@ -352,11 +349,9 @@ char *get_tracing_file(const char *name) ...@@ -352,11 +349,9 @@ char *get_tracing_file(const char *name)
if (!tracing) if (!tracing)
return NULL; return NULL;
file = malloc(strlen(tracing) + strlen(name) + 2); if (asprintf(&file, "%s/%s", tracing, name) < 0)
if (!file)
return NULL; return NULL;
sprintf(file, "%s/%s", tracing, name);
return file; return file;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册