summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-02-06 20:05:36 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2025-07-01 00:20:01 -0400
commit020e374b9bac4bc87d65d4378261cc45fa669438 (patch)
treea29846c04109d0c043f6d362f83e35fd2dd4a199
parenta631fa96a348913c6f0ba778139dbe66681d261e (diff)
seq_buf: seq_buf_human_readable_u64()
This adds a seq_buf wrapper for string_get_size(). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--include/linux/seq_buf.h4
-rw-r--r--lib/seq_buf.c10
2 files changed, 14 insertions, 0 deletions
diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
index 52791e070506..c055243ec206 100644
--- a/include/linux/seq_buf.h
+++ b/include/linux/seq_buf.h
@@ -173,4 +173,8 @@ int seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
void seq_buf_do_printk(struct seq_buf *s, const char *lvl);
+enum string_size_units;
+void seq_buf_human_readable_u64(struct seq_buf *s, u64 v,
+ const enum string_size_units units);
+
#endif /* _LINUX_SEQ_BUF_H */
diff --git a/lib/seq_buf.c b/lib/seq_buf.c
index f3f3436d60a9..3c41ca83a0c3 100644
--- a/lib/seq_buf.c
+++ b/lib/seq_buf.c
@@ -436,3 +436,13 @@ int seq_buf_hex_dump(struct seq_buf *s, const char *prefix_str, int prefix_type,
}
return 0;
}
+
+void seq_buf_human_readable_u64(struct seq_buf *s, u64 v, const enum string_size_units units)
+{
+ char *buf;
+ size_t size = seq_buf_get_buf(s, &buf);
+ int wrote = string_get_size(v, 1, units, buf, size);
+
+ seq_buf_commit(s, wrote);
+}
+EXPORT_SYMBOL(seq_buf_human_readable_u64);