perf probe: Check the return value of strbuf APIs
Check the return value of strbuf APIs in perf-probe related code, so that it can handle errors in strbuf. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20160510054707.6158.69861.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
5cea57f30a
commit
bf4d5f25c9
@@ -915,8 +915,7 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
|
||||
tmp = "*";
|
||||
else if (tag == DW_TAG_subroutine_type) {
|
||||
/* Function pointer */
|
||||
strbuf_add(buf, "(function_type)", 15);
|
||||
return 0;
|
||||
return strbuf_add(buf, "(function_type)", 15);
|
||||
} else {
|
||||
if (!dwarf_diename(&type))
|
||||
return -ENOENT;
|
||||
@@ -927,14 +926,10 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
|
||||
else if (tag == DW_TAG_enumeration_type)
|
||||
tmp = "enum ";
|
||||
/* Write a base name */
|
||||
strbuf_addf(buf, "%s%s", tmp, dwarf_diename(&type));
|
||||
return 0;
|
||||
return strbuf_addf(buf, "%s%s", tmp, dwarf_diename(&type));
|
||||
}
|
||||
ret = die_get_typename(&type, buf);
|
||||
if (ret == 0)
|
||||
strbuf_addstr(buf, tmp);
|
||||
|
||||
return ret;
|
||||
return ret ? ret : strbuf_addstr(buf, tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -951,12 +946,10 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
|
||||
ret = die_get_typename(vr_die, buf);
|
||||
if (ret < 0) {
|
||||
pr_debug("Failed to get type, make it unknown.\n");
|
||||
strbuf_add(buf, " (unknown_type)", 14);
|
||||
ret = strbuf_add(buf, " (unknown_type)", 14);
|
||||
}
|
||||
|
||||
strbuf_addf(buf, "\t%s", dwarf_diename(vr_die));
|
||||
|
||||
return 0;
|
||||
return ret < 0 ? ret : strbuf_addf(buf, "\t%s", dwarf_diename(vr_die));
|
||||
}
|
||||
|
||||
#ifdef HAVE_DWARF_GETLOCATIONS
|
||||
@@ -999,22 +992,24 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die,
|
||||
}
|
||||
|
||||
while ((offset = dwarf_ranges(&scopes[1], offset, &base,
|
||||
&start, &end)) > 0) {
|
||||
&start, &end)) > 0) {
|
||||
start -= entry;
|
||||
end -= entry;
|
||||
|
||||
if (first) {
|
||||
strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64,
|
||||
name, start, end);
|
||||
ret = strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64,
|
||||
name, start, end);
|
||||
first = false;
|
||||
} else {
|
||||
strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64,
|
||||
start, end);
|
||||
ret = strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64,
|
||||
start, end);
|
||||
}
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!first)
|
||||
strbuf_add(buf, "]>", 2);
|
||||
ret = strbuf_add(buf, "]>", 2);
|
||||
|
||||
out:
|
||||
free(scopes);
|
||||
@@ -1054,31 +1049,32 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)
|
||||
if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
while ((offset = dwarf_getlocations(
|
||||
&attr, offset, &base,
|
||||
&start, &end, &op, &nops)) > 0) {
|
||||
while ((offset = dwarf_getlocations(&attr, offset, &base,
|
||||
&start, &end, &op, &nops)) > 0) {
|
||||
if (start == 0) {
|
||||
/* Single Location Descriptions */
|
||||
ret = die_get_var_innermost_scope(sp_die, vr_die, buf);
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Location Lists */
|
||||
start -= entry;
|
||||
end -= entry;
|
||||
if (first) {
|
||||
strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64,
|
||||
name, start, end);
|
||||
ret = strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64,
|
||||
name, start, end);
|
||||
first = false;
|
||||
} else {
|
||||
strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64,
|
||||
start, end);
|
||||
ret = strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64,
|
||||
start, end);
|
||||
}
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!first)
|
||||
strbuf_add(buf, "]>", 2);
|
||||
|
||||
ret = strbuf_add(buf, "]>", 2);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user