summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-07-10 23:01:51 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-08-14 12:28:44 -0400
commitac68a58bab15e600fffbbc38be8ff917fcb71509 (patch)
tree34dfb0f1cf3d2d0b6959f96c8a3caa179f2d48a0
parent1faab594316b80a5ee3e5463b9506e40c1338001 (diff)
memory profiling: print negative numbers correctly
We shouldn't see negative numbers, but bugs happen, and this will print out something more sensible. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--lib/alloc_tag.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
index 63af296a5a87..a17a1696b265 100644
--- a/lib/alloc_tag.c
+++ b/lib/alloc_tag.c
@@ -57,11 +57,17 @@ static void allocinfo_stop(struct seq_file *m, void *arg)
static void alloc_tag_to_text(char *buf, struct codetag *ct)
{
struct alloc_tag *tag = ct_to_alloc_tag(ct);
- char val[10];
+ s64 bytes = alloc_tag_read(tag);
+ char val[10], *p = val;
- string_get_size(alloc_tag_read(tag), 1,
+ if (bytes < 0) {
+ *p++ = '-';
+ bytes = -bytes;
+ }
+
+ string_get_size(bytes, 1,
STRING_SIZE_BASE2|STRING_SIZE_NOSPACE,
- val, sizeof(val));
+ p, val + ARRAY_SIZE(val) - p);
buf += sprintf(buf, "%8s ", val);
buf += codetag_to_text(buf, ct);