[PATCH RESEND v1 10/13] perf arm-spe: Detect failure for snprintf()
From: Leo Yan
Date: Mon Aug 17 2020 - 10:55:04 EST
When any failure is returned from snprintf(), the event packet decoding
detects the failure and bail out with reporting failure code to up
layer.
Signed-off-by: Leo Yan <leo.yan@xxxxxxxxxx>
---
.../arm-spe-decoder/arm-spe-pkt-decoder.c | 27 ++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
index 78250c8d74ca..121414e4ae23 100644
--- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
+++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
@@ -262,68 +262,89 @@ int arm_spe_pkt_desc(const struct arm_spe_pkt *packet, char *buf,
ret = 0;
ret = snprintf(buf, buf_len, "EV");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
if (payload & SPE_EVT_PKT_GEN_EXCEPTION) {
ret = snprintf(buf, buf_len, " EXCEPTION-GEN");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (payload & SPE_EVT_PKT_ARCH_RETIRED) {
ret = snprintf(buf, buf_len, " RETIRED");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (payload & SPE_EVT_PKT_L1D_ACCESS) {
ret = snprintf(buf, buf_len, " L1D-ACCESS");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (payload & SPE_EVT_PKT_L1D_REFILL) {
ret = snprintf(buf, buf_len, " L1D-REFILL");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (payload & SPE_EVT_PKT_TLB_ACCESS) {
ret = snprintf(buf, buf_len, " TLB-ACCESS");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (payload & SPE_EVT_PKT_TLB_WALK) {
ret = snprintf(buf, buf_len, " TLB-REFILL");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (payload & SPE_EVT_PKT_NOT_TAKEN) {
ret = snprintf(buf, buf_len, " NOT-TAKEN");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (payload & SPE_EVT_PKT_MISPREDICTED) {
ret = snprintf(buf, buf_len, " MISPRED");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (idx > 1) {
if (payload & SPE_EVT_PKT_LLC_ACCESS) {
ret = snprintf(buf, buf_len, " LLC-ACCESS");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (payload & SPE_EVT_PKT_LLC_MISS) {
ret = snprintf(buf, buf_len, " LLC-REFILL");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
if (payload & SPE_EVT_PKT_REMOTE_ACCESS) {
ret = snprintf(buf, buf_len, " REMOTE-ACCESS");
+ if (ret < 0)
+ return ret;
buf += ret;
blen -= ret;
}
}
- if (ret < 0)
- return ret;
- blen -= ret;
return buf_len - blen;
}
case ARM_SPE_OP_TYPE:
--
2.17.1