fs/seq_file: introduce seq_hex_dump() helper
Subsystems (8)
v5 cover fs/seq_file: introduce seq_hex_dump() helper
This introduces a new helper and switches current users to use it. All patches are compiled tested, kmemleak is tested by its own test suit.
Changelog v5:
- remove already applied patches (hexdump)
- postpone patch for saa7164 since conficts (needs investigation)
- rebase on top of recent linux-next
Changelog v4:
- hexdump is amended to return value from which we can check an overflow (patches 1/12 - 4/12)
- seq_hex_dump pushes bytes directly to buffer and returns an error in case of overflow (addresses Al Viro's comment)
- append Acked-by for patches 8/12 and 9/12
- convert more users (patches 10/12 - 12/12)
Changelog v3:
- append Mauro's Ack
- rebase on top of recent linux-next
Changelog v2:
- append Acked-by and Reviewed-by tags
- update commit messages in patches 3/5. and 5/5
- update line size to be 32 bytes instead of 16 in patch 3/5
- Joe found that output is changed in patch 4/5, thus I update commit message there
Andy Shevchenko (6):
seq_file: provide an analogue of print_hex_dump()
crypto: qat - use seq_hex_dump() to dump buffers
parisc: use seq_hex_dump() to dump buffers [S390] zcrypt: use seq_hex_dump() to dump buffers
kmemleak: use seq_hex_dump() to dump buffers
wil6210: use seq_hex_dump() to dump buffers
.../crypto/qat/qat_common/adf_transport_debug.c | 16 ++------- drivers/net/wireless/ath/wil6210/debugfs.c | 35 ++++-------------- drivers/parisc/ccio-dma.c | 13 ++----- drivers/parisc/sba_iommu.c | 9 ++--- drivers/s390/crypto/zcrypt_api.c | 10 +----- fs/seq_file.c | 42 ++++++++++++++++++++++ include/linux/seq_file.h | 4 +++ mm/kmemleak.c | 21 ++++------- 8 files changed, 67 insertions(+), 83 deletions(-)
Signature · 1 line
2.1.4
PATCH v5 1/6 seq_file: provide an analogue of print_hex_dump()
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.
--- fs/seq_file.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/linux/seq_file.h | 4 ++++ 2 files changed, 46 insertions(+)
fs/seq_file.c +42 -0
@@ -12,6 +12,7 @@#include <linux/slab.h> #include <linux/cred.h> #include <linux/mm.h> +#include <linux/printk.h> #include <asm/uaccess.h> #include <asm/page.h>
@@ -765,6 +766,47 @@ void seq_pad(struct seq_file *m, char c) }EXPORT_SYMBOL (seq_pad); +/* A complete analogue of print_hex_dump() */ +void seq_hex_dump (struct seq_file *m,const char *prefix_str,int prefix_type, +int rowsize,int groupsize,const void *buf,size_t len, +bool ascii) +{ +const u8 *ptr = buf; +int i, linelen, remaining = len; +int ret; + +if (rowsize !=16 && rowsize !=32 ) + rowsize =16 ; + +for (i =0 ; i < len && !seq_has_overflowed (m); i += rowsize) { + linelen =min (remaining, rowsize); + remaining -= rowsize; + +switch (prefix_type) { +case DUMP_PREFIX_ADDRESS : +seq_printf (m,"%s%p: " , prefix_str, ptr + i); +break ; +case DUMP_PREFIX_OFFSET : +seq_printf (m,"%s%.8x: " , prefix_str, i); +break ; +default : +seq_printf (m,"%s" , prefix_str); +break ; + } + + ret =hex_dump_to_buffer (ptr + i, linelen, rowsize, groupsize, + m->buf + m->count, m->size - m->count, + ascii); +if (ret >= m->size - m->count) { +seq_set_overflow (m); + }else { + m->count += ret; +seq_putc (m,'\n' ); + } + } +} +EXPORT_SYMBOL (seq_hex_dump); +struct list_head *seq_list_start (struct list_head *head,loff_t pos) {struct list_head *lh;
include/linux/seq_file.h +4 -0
@@ -127,6 +127,10 @@ void seq_put_decimal_ull(struct seq_file *m, char delimiter,void seq_put_decimal_ll (struct seq_file *m,char delimiter,long long num);void seq_escape (struct seq_file *m,const char *s,const char *esc); +void seq_hex_dump (struct seq_file *m,const char *prefix_str,int prefix_type, +int rowsize,int groupsize,const void *buf,size_t len, +bool ascii); +int seq_path (struct seq_file *,const struct path *,const char *);int seq_file_path (struct seq_file *,struct file *,const char *);int seq_dentry (struct seq_file *,struct dentry *,const char *);
Signature · 1 line
2.1.4
PATCH v5 2/6 crypto: qat - use seq_hex_dump() to dump buffers
In reply to Andy ShevchenkoInstead of custom approach let's use recently introduced seq_hex_dump() helper.
--- drivers/crypto/qat/qat_common/adf_transport_debug.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/crypto/qat/qat_common/adf_transport_debug.c +2 -14
@@ -86,9 +86,7 @@ static int adf_ring_show(struct seq_file *sfile, void *v) {struct adf_etr_ring_data *ring = sfile->private;struct adf_etr_bank_data *bank = ring->bank; -uint32_t *msg = v;void __iomem *csr = ring->bank->csr_addr; -int i, x;if (v ==SEQ_START_TOKEN ) {int head, tail, empty;
@@ -113,18 +111,8 @@ static int adf_ring_show(struct seq_file *sfile, void *v)seq_puts (sfile,"----------- Ring data ------------\n" );return 0 ; } -seq_printf (sfile,"%p:" , msg); - x =0 ; - i =0 ; -for (; i < (ADF_MSG_SIZE_TO_BYTES (ring->msg_size) >>2 ); i++) { -seq_printf (sfile," %08X" , *(msg + i)); -if ((ADF_MSG_SIZE_TO_BYTES (ring->msg_size) >>2 ) != i +1 && - (++x ==8 )) { -seq_printf (sfile,"\n%p:" , msg + i +1 ); - x =0 ; - } - } -seq_puts (sfile,"\n" ); +seq_hex_dump (sfile,"" ,DUMP_PREFIX_ADDRESS ,32 ,4 , + v,ADF_MSG_SIZE_TO_BYTES (ring->msg_size), false);return 0 ; }
Signature · 1 line
2.1.4
PATCH v5 3/6 parisc: use seq_hex_dump() to dump buffers
In reply to Andy ShevchenkoInstead of custom approach let's use recently introduced seq_hex_dump() helper.
In one case it changes the output from
1111111122222222333333334444444455555555666666667777777788888888 to 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888
though it seems it prints same data (by meaning) in both cases. I decide to choose to use the space divided one.
--- drivers/parisc/ccio-dma.c | 13 +++---------- drivers/parisc/sba_iommu.c | 9 ++------- 2 files changed, 5 insertions(+), 17 deletions(-)
drivers/parisc/ccio-dma.c +3 -10
@@ -1103,16 +1103,9 @@ static int ccio_proc_bitmap_info(struct seq_file *m, void *p)struct ioc *ioc = ioc_list;while (ioc !=NULL ) { -u32 *res_ptr = (u32 *)ioc->res_map; -int j; - -for (j =0 ; j < (ioc->res_size /sizeof (u32)); j++) { -if ((j &7 ) ==0 ) -seq_puts (m,"\n " ); -seq_printf (m,"%08x" , *res_ptr); - res_ptr++; - } -seq_puts (m,"\n\n" ); +seq_hex_dump (m," " ,DUMP_PREFIX_NONE ,32 ,4 , ioc->res_map, + ioc->res_size, false); +seq_putc (m,'\n' ); ioc = ioc->next;break ;/* XXX - remove me */ }
drivers/parisc/sba_iommu.c +2 -7
@@ -1854,14 +1854,9 @@ sba_proc_bitmap_info(struct seq_file *m, void *p) {struct sba_device *sba_dev = sba_list;struct ioc *ioc = &sba_dev->ioc[0 ];/* FIXME: Multi-IOC support! */ -unsigned int *res_ptr = (unsigned int *)ioc->res_map; -int i; -for (i =0 ; i < (ioc->res_size/sizeof (unsigned int )); ++i, ++res_ptr) { -if ((i &7 ) ==0 ) -seq_puts (m,"\n " ); -seq_printf (m," %08x" , *res_ptr); - } +seq_hex_dump (m," " ,DUMP_PREFIX_NONE ,32 ,4 , ioc->res_map, + ioc->res_size, false);seq_putc (m,'\n' );return 0 ;
Signature · 1 line
2.1.4
PATCH v5 4/6 zcrypt: use seq_hex_dump() to dump buffers
In reply to Andy ShevchenkoInstead of custom approach let's use recently introduced seq_hex_dump() helper.
--- drivers/s390/crypto/zcrypt_api.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/s390/crypto/zcrypt_api.c +1 -9
@@ -1206,16 +1206,8 @@ static void sprinthx(unsigned char *title, struct seq_file *m,static void sprinthx4 (unsigned char *title,struct seq_file *m,unsigned int *array,unsigned int len) { -int r; -seq_printf (m,"\n%s\n" , title); -for (r =0 ; r < len; r++) { -if ((r %8 ) ==0 ) -seq_printf (m," " ); -seq_printf (m,"%08X " , array[r]); -if ((r %8 ) ==7 ) -seq_putc (m,'\n' ); - } +seq_hex_dump (m," " ,DUMP_PREFIX_NONE ,32 ,4 , array, len, false);seq_putc (m,'\n' ); }
Signature · 1 line
2.1.4
PATCH v5 5/6 kmemleak: use seq_hex_dump() to dump buffers
In reply to Andy ShevchenkoInstead of custom approach let's use recently introduced seq_hex_dump() helper.
--- mm/kmemleak.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
mm/kmemleak.c +6 -15
@@ -302,23 +302,14 @@ static void hex_dump_object(struct seq_file *seq, struct kmemleak_object *object) {const u8 *ptr = (const u8 *)object->pointer; -int i, len, remaining; -unsigned char linebuf[HEX_ROW_SIZE *5 ]; +size_t len;/* limit the number of lines to HEX_MAX_LINES */ - remaining = len = -min (object->size, (size_t )(HEX_MAX_LINES *HEX_ROW_SIZE )); - -seq_printf (seq," hex dump (first %d bytes):\n" , len); -for (i =0 ; i < len; i +=HEX_ROW_SIZE ) { -int linelen =min (remaining,HEX_ROW_SIZE ); - - remaining -=HEX_ROW_SIZE ; -hex_dump_to_buffer (ptr + i, linelen,HEX_ROW_SIZE , -HEX_GROUP_SIZE , linebuf,sizeof (linebuf), -HEX_ASCII ); -seq_printf (seq," %s\n" , linebuf); - } + len =min_t (size_t, object->size,HEX_MAX_LINES *HEX_ROW_SIZE ); + +seq_printf (seq," hex dump (first %zu bytes):\n" , len); +seq_hex_dump (seq," " ,DUMP_PREFIX_NONE ,HEX_ROW_SIZE , +HEX_GROUP_SIZE , ptr, len,HEX_ASCII ); }/*
Signature · 1 line
2.1.4
Re: [PATCH v5 5/6] kmemleak: use seq_hex_dump() to dump buffers
Quoted 3 lines · Andy Shevchenko
Instead of custom approach let's use recently introduced
seq_hex_dump()helper.Signed-off-by Andy Shevchenko <[email protected]>
PATCH v5 6/6 wil6210: use seq_hex_dump() to dump buffers
In reply to Andy ShevchenkoInstead of custom approach let's use recently introduced seq_hex_dump() helper.
--- drivers/net/wireless/ath/wil6210/debugfs.c | 35 ++++++------------------------ 1 file changed, 7 insertions(+), 28 deletions(-)
drivers/net/wireless/ath/wil6210/debugfs.c +7 -28
@@ -156,6 +156,12 @@ static const struct file_operations fops_vring = { .llseek = seq_lseek, }; +static void wil_seq_hexdump (struct seq_file *s,void *p,int len, +const char *prefix) +{ +seq_hex_dump (s, prefix,DUMP_PREFIX_NONE ,16 ,1 , p, len, false); +} +static void wil_print_ring (struct seq_file *s,const char *prefix,void __iomem *off) {
@@ -212,8 +218,6 @@ static void wil_print_ring(struct seq_file *s, const char *prefix,le16_to_cpu (hdr.seq), len, le16_to_cpu(hdr.type), hdr.flags);if (len <=MAX_MBOXITEM_SIZE ) { -int n =0 ; -char printbuf[16 *3 +2 ];unsigned char databuf[MAX_MBOXITEM_SIZE ];void __iomem *src =wmi_buffer (wil, d.addr) +sizeof (struct wil6210_mbox_hdr );
@@ -223,16 +227,7 @@ static void wil_print_ring(struct seq_file *s, const char *prefix,* reading header */ wil_memcpy_fromio_32 (databuf, src, len); -while (n < len) { -int l =min (len - n,16 ); - -hex_dump_to_buffer (databuf + n, l, -16 ,1 , printbuf, -sizeof (printbuf), - false); -seq_printf (s," : %s\n" , printbuf); - n += l; - } +wil_seq_hexdump (s, databuf, len," : " ); } }else {seq_puts (s,"\n" );
@@ -867,22 +862,6 @@ static const struct file_operations fops_wmi = { .open = simple_open, }; -static void wil_seq_hexdump (struct seq_file *s,void *p,int len, -const char *prefix) -{ -char printbuf[16 *3 +2 ]; -int i =0 ; - -while (i < len) { -int l =min (len - i,16 ); - -hex_dump_to_buffer (p + i, l,16 ,1 , printbuf, -sizeof (printbuf), false); -seq_printf (s,"%s%s\n" , prefix, printbuf); - i += l; - } -} -static void wil_seq_print_skb (struct seq_file *s,struct sk_buff *skb) {int i =0 ;
Signature · 1 line
2.1.4