aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2015-09-09 18:38:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-10 16:29:01 -0400
commit37607102c4426cf92aeb5da1b1d9a79ba6d95e3f (patch)
tree4690fa938f30a2104eb4fe92de49a4b5386d021d /fs
parent40f705a736eac10e7dca7ab5dd5ed675a6df031d (diff)
seq_file: provide an analogue of print_hex_dump()
This introduces a new helper and switches current users to use it. All patches are compiled tested. kmemleak is tested via its own test suite. This patch (of 6): The new seq_hex_dump() is a complete analogue of print_hex_dump(). We have few users of this functionality already. It allows to reduce their codebase. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Joe Perches <joe@perches.com> Cc: Tadeusz Struk <tadeusz.struk@intel.com> Cc: Helge Deller <deller@gmx.de> Cc: Ingo Tuchscherer <ingo.tuchscherer@de.ibm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Vladimir Kondratiev <qca_vkondrat@qca.qualcomm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/seq_file.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c
index ce9e39fd5daf..263b125dbcf4 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -12,6 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/cred.h> 13#include <linux/cred.h>
14#include <linux/mm.h> 14#include <linux/mm.h>
15#include <linux/printk.h>
15 16
16#include <asm/uaccess.h> 17#include <asm/uaccess.h>
17#include <asm/page.h> 18#include <asm/page.h>
@@ -773,6 +774,47 @@ void seq_pad(struct seq_file *m, char c)
773} 774}
774EXPORT_SYMBOL(seq_pad); 775EXPORT_SYMBOL(seq_pad);
775 776
777/* A complete analogue of print_hex_dump() */
778void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
779 int rowsize, int groupsize, const void *buf, size_t len,
780 bool ascii)
781{
782 const u8 *ptr = buf;
783 int i, linelen, remaining = len;
784 int ret;
785
786 if (rowsize != 16 && rowsize != 32)
787 rowsize = 16;
788
789 for (i = 0; i < len && !seq_has_overflowed(m); i += rowsize) {
790 linelen = min(remaining, rowsize);
791 remaining -= rowsize;
792
793 switch (prefix_type) {
794 case DUMP_PREFIX_ADDRESS:
795 seq_printf(m, "%s%p: ", prefix_str, ptr + i);
796 break;
797 case DUMP_PREFIX_OFFSET:
798 seq_printf(m, "%s%.8x: ", prefix_str, i);
799 break;
800 default:
801 seq_printf(m, "%s", prefix_str);
802 break;
803 }
804
805 ret = hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
806 m->buf + m->count, m->size - m->count,
807 ascii);
808 if (ret >= m->size - m->count) {
809 seq_set_overflow(m);
810 } else {
811 m->count += ret;
812 seq_putc(m, '\n');
813 }
814 }
815}
816EXPORT_SYMBOL(seq_hex_dump);
817
776struct list_head *seq_list_start(struct list_head *head, loff_t pos) 818struct list_head *seq_list_start(struct list_head *head, loff_t pos)
777{ 819{
778 struct list_head *lh; 820 struct list_head *lh;