From: tip-bot for Masami Hiramatsu <mhiramat@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org, paulus@samba.org,
hpa@zytor.com, mingo@redhat.com, efault@gmx.de,
peterz@infradead.org, fweisbec@gmail.com, tglx@linutronix.de,
mhiramat@redhat.com, mingo@elte.hu
Subject: [tip:perf/core] perf probe: Remove xzalloc() from util/probe-{event, finder}.c
Date: Thu, 15 Apr 2010 07:30:08 GMT [thread overview]
Message-ID: <tip-e334016f1d7250a6523b3a44ccecfe23af6e2f57@git.kernel.org> (raw)
In-Reply-To: <20100412171749.3790.33303.stgit@localhost6.localdomain6>
Commit-ID: e334016f1d7250a6523b3a44ccecfe23af6e2f57
Gitweb: http://git.kernel.org/tip/e334016f1d7250a6523b3a44ccecfe23af6e2f57
Author: Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Mon, 12 Apr 2010 13:17:49 -0400
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 14 Apr 2010 17:28:45 -0300
perf probe: Remove xzalloc() from util/probe-{event, finder}.c
Remove all xzalloc() calls from util/probe-{event,finder}.c since
it may cause 'sudden death' in utility functions and it makes
reusing it from other code difficult.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20100412171749.3790.33303.stgit@localhost6.localdomain6>
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-event.c | 69 +++++++++++++++++++++++++++++----------
tools/perf/util/probe-finder.c | 25 ++++++++++----
2 files changed, 69 insertions(+), 25 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index bd68f7b..aacbf73 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -556,7 +556,9 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
fieldp = &arg->field;
do {
- *fieldp = xzalloc(sizeof(struct perf_probe_arg_field));
+ *fieldp = zalloc(sizeof(struct perf_probe_arg_field));
+ if (*fieldp == NULL)
+ return -ENOMEM;
if (*tmp == '.') {
str = tmp + 1;
(*fieldp)->ref = false;
@@ -608,7 +610,11 @@ int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
/* Copy arguments and ensure return probe has no C argument */
pev->nargs = argc - 1;
- pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs);
+ pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
+ if (pev->args == NULL) {
+ ret = -ENOMEM;
+ goto out;
+ }
for (i = 0; i < pev->nargs && ret >= 0; i++) {
ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]);
if (ret >= 0 &&
@@ -680,7 +686,11 @@ int parse_kprobe_trace_command(const char *cmd, struct kprobe_trace_event *tev)
tp->offset = 0;
tev->nargs = argc - 2;
- tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
+ tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
+ if (tev->args == NULL) {
+ ret = -ENOMEM;
+ goto out;
+ }
for (i = 0; i < tev->nargs; i++) {
p = strchr(argv[i + 2], '=');
if (p) /* We don't need which register is assigned. */
@@ -745,7 +755,11 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
char offs[32] = "", line[32] = "", file[32] = "";
int ret, len;
- buf = xzalloc(MAX_CMDLEN);
+ buf = zalloc(MAX_CMDLEN);
+ if (buf == NULL) {
+ ret = -ENOMEM;
+ goto error;
+ }
if (pp->offset) {
ret = e_snprintf(offs, 32, "+%lu", pp->offset);
if (ret <= 0)
@@ -781,7 +795,8 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
error:
pr_debug("Failed to synthesize perf probe point: %s",
strerror(-ret));
- free(buf);
+ if (buf)
+ free(buf);
return NULL;
}
@@ -890,7 +905,10 @@ char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev)
char *buf;
int i, len, ret;
- buf = xzalloc(MAX_CMDLEN);
+ buf = zalloc(MAX_CMDLEN);
+ if (buf == NULL)
+ return NULL;
+
len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s+%lu",
tp->retprobe ? 'r' : 'p',
tev->group, tev->event,
@@ -929,7 +947,9 @@ int convert_to_perf_probe_event(struct kprobe_trace_event *tev,
/* Convert trace_arg to probe_arg */
pev->nargs = tev->nargs;
- pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs);
+ pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
+ if (pev->args == NULL)
+ return -ENOMEM;
for (i = 0; i < tev->nargs && ret >= 0; i++)
if (tev->args[i].name)
pev->args[i].name = xstrdup(tev->args[i].name);
@@ -1326,25 +1346,31 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev,
struct kprobe_trace_event **tevs)
{
struct symbol *sym;
- int ntevs = 0, i;
+ int ret = 0, i;
struct kprobe_trace_event *tev;
/* Convert perf_probe_event with debuginfo */
- ntevs = try_to_find_kprobe_trace_events(pev, tevs);
- if (ntevs != 0)
- return ntevs;
+ ret = try_to_find_kprobe_trace_events(pev, tevs);
+ if (ret != 0)
+ return ret;
/* Allocate trace event buffer */
- ntevs = 1;
- tev = *tevs = xzalloc(sizeof(struct kprobe_trace_event));
+ tev = *tevs = zalloc(sizeof(struct kprobe_trace_event));
+ if (tev == NULL)
+ return -ENOMEM;
/* Copy parameters */
tev->point.symbol = xstrdup(pev->point.function);
tev->point.offset = pev->point.offset;
tev->nargs = pev->nargs;
if (tev->nargs) {
- tev->args = xzalloc(sizeof(struct kprobe_trace_arg)
- * tev->nargs);
+ tev->args = zalloc(sizeof(struct kprobe_trace_arg)
+ * tev->nargs);
+ if (tev->args == NULL) {
+ free(tev);
+ *tevs = NULL;
+ return -ENOMEM;
+ }
for (i = 0; i < tev->nargs; i++) {
if (pev->args[i].name)
tev->args[i].name = xstrdup(pev->args[i].name);
@@ -1360,9 +1386,14 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev,
if (!sym) {
pr_warning("Kernel symbol \'%s\' not found.\n",
tev->point.symbol);
+ clear_kprobe_trace_event(tev);
+ free(tev);
+ *tevs = NULL;
return -ENOENT;
- }
- return ntevs;
+ } else
+ ret = 1;
+
+ return ret;
}
struct __event_package {
@@ -1377,7 +1408,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
int i, j, ret;
struct __event_package *pkgs;
- pkgs = xzalloc(sizeof(struct __event_package) * npevs);
+ pkgs = zalloc(sizeof(struct __event_package) * npevs);
+ if (pkgs == NULL)
+ return -ENOMEM;
/* Init vmlinux path */
ret = init_vmlinux();
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 54daa91..ce1ac82 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -111,7 +111,7 @@ static int strtailcmp(const char *s1, const char *s2)
/* Line number list operations */
/* Add a line to line number list */
-static void line_list__add_line(struct list_head *head, unsigned int line)
+static int line_list__add_line(struct list_head *head, unsigned int line)
{
struct line_node *ln;
struct list_head *p;
@@ -122,16 +122,19 @@ static void line_list__add_line(struct list_head *head, unsigned int line)
p = &ln->list;
goto found;
} else if (ln->line == line) /* Already exist */
- return ;
+ return 1;
}
/* List is empty, or the smallest entry */
p = head;
found:
pr_debug("line list: add a line %u\n", line);
- ln = xzalloc(sizeof(struct line_node));
+ ln = zalloc(sizeof(struct line_node));
+ if (ln == NULL)
+ return -ENOMEM;
ln->line = line;
INIT_LIST_HEAD(&ln->list);
list_add(&ln->list, p);
+ return 0;
}
/* Check if the line in line number list */
@@ -423,7 +426,9 @@ static int convert_location(Dwarf_Op *op, struct probe_finder *pf)
tvar->value = xstrdup(regs);
if (ref) {
- tvar->ref = xzalloc(sizeof(struct kprobe_trace_arg_ref));
+ tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref));
+ if (tvar->ref == NULL)
+ return -ENOMEM;
tvar->ref->offset = (long)offs;
}
return 0;
@@ -500,7 +505,9 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,
return -EINVAL;
}
- ref = xzalloc(sizeof(struct kprobe_trace_arg_ref));
+ ref = zalloc(sizeof(struct kprobe_trace_arg_ref));
+ if (ref == NULL)
+ return -ENOMEM;
if (*ref_ptr)
(*ref_ptr)->next = ref;
else
@@ -680,7 +687,9 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
/* Find each argument */
tev->nargs = pf->pev->nargs;
- tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
+ tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
+ if (tev->args == NULL)
+ return -ENOMEM;
for (i = 0; i < pf->pev->nargs; i++) {
pf->pvar = &pf->pev->args[i];
pf->tvar = &tev->args[i];
@@ -938,7 +947,9 @@ int find_kprobe_trace_events(int fd, struct perf_probe_event *pev,
Dwarf *dbg;
int ret = 0;
- pf.tevs = xzalloc(sizeof(struct kprobe_trace_event) * MAX_PROBES);
+ pf.tevs = zalloc(sizeof(struct kprobe_trace_event) * MAX_PROBES);
+ if (pf.tevs == NULL)
+ return -ENOMEM;
*tevs = pf.tevs;
pf.ntevs = 0;
next prev parent reply other threads:[~2010-04-15 7:30 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-12 17:16 [PATCH -tip v3 00/10] perf-probe updates - data-structure support improvements, etc Masami Hiramatsu
2010-04-12 17:16 ` [PATCH -tip v3 01/10] perf probe: Support argument name Masami Hiramatsu
2010-04-15 7:27 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-04-12 17:17 ` [PATCH -tip v3 02/10] perf probe: Use the last field name as the " Masami Hiramatsu
2010-04-15 7:28 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-04-12 17:17 ` [PATCH -tip v3 03/10] tracing/kprobes: Support basic types on dynamic events Masami Hiramatsu
2010-04-15 7:28 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-04-12 17:17 ` [PATCH -tip v3 04/10] perf probe: Query basic types from debuginfo Masami Hiramatsu
2010-04-12 17:45 ` Arnaldo Carvalho de Melo
2010-04-15 7:28 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-04-12 17:17 ` [PATCH -tip v3 05/10] perf probe: Support basic type casting Masami Hiramatsu
2010-04-15 7:29 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-04-12 17:17 ` [PATCH -tip v3 06/10] perf probe: Support DW_OP_call_frame_cfa in debuginfo Masami Hiramatsu
2010-04-15 7:29 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-05-07 16:34 ` Robert Richter
2010-05-07 17:16 ` Masami Hiramatsu
2010-05-07 18:31 ` Arnaldo Carvalho de Melo
2010-05-07 19:12 ` Masami Hiramatsu
2010-05-07 19:47 ` Masami Hiramatsu
2010-05-07 20:04 ` Robert Richter
2010-04-12 17:17 ` [PATCH -tip v3 07/10] perf probe: Remove die() from probe-finder code Masami Hiramatsu
2010-04-15 7:29 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-04-12 17:17 ` [PATCH -tip v3 08/10] perf probe: Remove die() from probe-event code Masami Hiramatsu
2010-04-15 7:29 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-04-12 17:17 ` [PATCH -tip v3 09/10] perf probe: Remove xzalloc() from util/probe-{event, finder}.c Masami Hiramatsu
2010-04-15 7:30 ` tip-bot for Masami Hiramatsu [this message]
2010-04-12 17:17 ` [PATCH -tip v3 10/10] perf probe: Remove xstrdup()/xstrndup() " Masami Hiramatsu
2010-04-15 7:30 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-04-12 17:49 ` [PATCH -tip v3 00/10] perf-probe updates - data-structure support improvements, etc Arnaldo Carvalho de Melo
2010-04-13 9:14 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-e334016f1d7250a6523b3a44ccecfe23af6e2f57@git.kernel.org \
--to=mhiramat@redhat.com \
--cc=acme@redhat.com \
--cc=efault@gmx.de \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox