[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231122232515.177833-2-kent.overstreet@linux.dev>
Date: Wed, 22 Nov 2023 18:25:06 -0500
From: Kent Overstreet <kent.overstreet@...ux.dev>
To: linux-mm@...ck.org, linux-kernel@...r.kernel.org
Cc: Kent Overstreet <kent.overstreet@...ux.dev>
Subject: [PATCH 1/7] seq_buf: seq_buf_human_readable_u64()
This adds a seq_buf wrapper for string_get_size().
Signed-off-by: Kent Overstreet <kent.overstreet@...ux.dev>
---
include/linux/seq_buf.h | 4 ++++
lib/seq_buf.c | 10 ++++++++++
2 files changed, 14 insertions(+)
diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
index 5fb1f12c33f9..dfcd0f367d6a 100644
--- a/include/linux/seq_buf.h
+++ b/include/linux/seq_buf.h
@@ -171,4 +171,8 @@ 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 010c730ca7fc..9d4e4d5f43b4 100644
--- a/lib/seq_buf.c
+++ b/lib/seq_buf.c
@@ -425,3 +425,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);
--
2.42.0
Powered by blists - more mailing lists