* [PATCH v5 0/6] fs/seq_file: introduce seq_hex_dump() helper
@ 2015-07-07 17:04 Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 1/6] seq_file: provide an analogue of print_hex_dump() Andy Shevchenko
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Andy Shevchenko @ 2015-07-07 17:04 UTC (permalink / raw)
To: Alexander Viro, linux-kernel, Joe Perches, Andrew Morton,
Tadeusz Struk, Helge Deller, Ingo Tuchscherer, Catalin Marinas,
Vladimir Kondratiev
Cc: Andy Shevchenko
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(-)
--
2.1.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v5 1/6] seq_file: provide an analogue of print_hex_dump()
2015-07-07 17:04 [PATCH v5 0/6] fs/seq_file: introduce seq_hex_dump() helper Andy Shevchenko
@ 2015-07-07 17:04 ` Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 2/6] crypto: qat - use seq_hex_dump() to dump buffers Andy Shevchenko
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2015-07-07 17:04 UTC (permalink / raw)
To: Alexander Viro, linux-kernel, Joe Perches, Andrew Morton,
Tadeusz Struk, Helge Deller, Ingo Tuchscherer, Catalin Marinas,
Vladimir Kondratiev
Cc: Andy Shevchenko
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>
---
fs/seq_file.c | 42 ++++++++++++++++++++++++++++++++++++++++++
include/linux/seq_file.h | 4 ++++
2 files changed, 46 insertions(+)
diff --git a/fs/seq_file.c b/fs/seq_file.c
index f46d526..225586e 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -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;
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index a629dd1..8c60c0e 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -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 *);
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v5 2/6] crypto: qat - use seq_hex_dump() to dump buffers
2015-07-07 17:04 [PATCH v5 0/6] fs/seq_file: introduce seq_hex_dump() helper Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 1/6] seq_file: provide an analogue of print_hex_dump() Andy Shevchenko
@ 2015-07-07 17:04 ` Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 3/6] parisc: " Andy Shevchenko
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2015-07-07 17:04 UTC (permalink / raw)
To: Alexander Viro, linux-kernel, Joe Perches, Andrew Morton,
Tadeusz Struk, Helge Deller, Ingo Tuchscherer, Catalin Marinas,
Vladimir Kondratiev
Cc: Andy Shevchenko
Instead of custom approach let's use recently introduced seq_hex_dump() helper.
Acked-by: Tadeusz Struk <tadeusz.struk@intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/crypto/qat/qat_common/adf_transport_debug.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/drivers/crypto/qat/qat_common/adf_transport_debug.c b/drivers/crypto/qat/qat_common/adf_transport_debug.c
index e419869..52340b9 100644
--- a/drivers/crypto/qat/qat_common/adf_transport_debug.c
+++ b/drivers/crypto/qat/qat_common/adf_transport_debug.c
@@ -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;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v5 3/6] parisc: use seq_hex_dump() to dump buffers
2015-07-07 17:04 [PATCH v5 0/6] fs/seq_file: introduce seq_hex_dump() helper Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 1/6] seq_file: provide an analogue of print_hex_dump() Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 2/6] crypto: qat - use seq_hex_dump() to dump buffers Andy Shevchenko
@ 2015-07-07 17:04 ` Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 4/6] [S390] zcrypt: " Andy Shevchenko
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2015-07-07 17:04 UTC (permalink / raw)
To: Alexander Viro, linux-kernel, Joe Perches, Andrew Morton,
Tadeusz Struk, Helge Deller, Ingo Tuchscherer, Catalin Marinas,
Vladimir Kondratiev
Cc: Andy Shevchenko
Instead 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.
Acked-by: Helge Deller <deller@gmx.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/parisc/ccio-dma.c | 13 +++----------
drivers/parisc/sba_iommu.c | 9 ++-------
2 files changed, 5 insertions(+), 17 deletions(-)
diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
index 02ff84f..957b421 100644
--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -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 */
}
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index f1441e4..225049b 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -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;
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v5 4/6] [S390] zcrypt: use seq_hex_dump() to dump buffers
2015-07-07 17:04 [PATCH v5 0/6] fs/seq_file: introduce seq_hex_dump() helper Andy Shevchenko
` (2 preceding siblings ...)
2015-07-07 17:04 ` [PATCH v5 3/6] parisc: " Andy Shevchenko
@ 2015-07-07 17:04 ` Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 5/6] kmemleak: " Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 6/6] wil6210: " Andy Shevchenko
5 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2015-07-07 17:04 UTC (permalink / raw)
To: Alexander Viro, linux-kernel, Joe Perches, Andrew Morton,
Tadeusz Struk, Helge Deller, Ingo Tuchscherer, Catalin Marinas,
Vladimir Kondratiev
Cc: Andy Shevchenko
Instead of custom approach let's use recently introduced seq_hex_dump() helper.
Acked-by: Ingo Tuchscherer <ingo.tuchscherer@de.ibm.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/s390/crypto/zcrypt_api.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 01bf1f5..4eb4554 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -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');
}
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v5 5/6] kmemleak: use seq_hex_dump() to dump buffers
2015-07-07 17:04 [PATCH v5 0/6] fs/seq_file: introduce seq_hex_dump() helper Andy Shevchenko
` (3 preceding siblings ...)
2015-07-07 17:04 ` [PATCH v5 4/6] [S390] zcrypt: " Andy Shevchenko
@ 2015-07-07 17:04 ` Andy Shevchenko
2015-07-08 9:20 ` Catalin Marinas
2015-07-07 17:04 ` [PATCH v5 6/6] wil6210: " Andy Shevchenko
5 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2015-07-07 17:04 UTC (permalink / raw)
To: Alexander Viro, linux-kernel, Joe Perches, Andrew Morton,
Tadeusz Struk, Helge Deller, Ingo Tuchscherer, Catalin Marinas,
Vladimir Kondratiev
Cc: Andy Shevchenko
Instead of custom approach let's use recently introduced seq_hex_dump() helper.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
mm/kmemleak.c | 21 ++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index cf79f11..b034c62 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -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);
}
/*
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v5 6/6] wil6210: use seq_hex_dump() to dump buffers
2015-07-07 17:04 [PATCH v5 0/6] fs/seq_file: introduce seq_hex_dump() helper Andy Shevchenko
` (4 preceding siblings ...)
2015-07-07 17:04 ` [PATCH v5 5/6] kmemleak: " Andy Shevchenko
@ 2015-07-07 17:04 ` Andy Shevchenko
5 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2015-07-07 17:04 UTC (permalink / raw)
To: Alexander Viro, linux-kernel, Joe Perches, Andrew Morton,
Tadeusz Struk, Helge Deller, Ingo Tuchscherer, Catalin Marinas,
Vladimir Kondratiev
Cc: Andy Shevchenko
Instead of custom approach let's use recently introduced seq_hex_dump() helper.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/net/wireless/ath/wil6210/debugfs.c | 35 ++++++------------------------
1 file changed, 7 insertions(+), 28 deletions(-)
diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
index 75219a1..7f07cf5 100644
--- a/drivers/net/wireless/ath/wil6210/debugfs.c
+++ b/drivers/net/wireless/ath/wil6210/debugfs.c
@@ -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;
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v5 5/6] kmemleak: use seq_hex_dump() to dump buffers
2015-07-07 17:04 ` [PATCH v5 5/6] kmemleak: " Andy Shevchenko
@ 2015-07-08 9:20 ` Catalin Marinas
0 siblings, 0 replies; 8+ messages in thread
From: Catalin Marinas @ 2015-07-08 9:20 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Alexander Viro, linux-kernel, Joe Perches, Andrew Morton,
Tadeusz Struk, Helge Deller, Ingo Tuchscherer,
Vladimir Kondratiev
On Tue, Jul 07, 2015 at 06:04:51PM +0100, Andy Shevchenko wrote:
> Instead of custom approach let's use recently introduced seq_hex_dump() helper.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-07-08 9:20 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-07 17:04 [PATCH v5 0/6] fs/seq_file: introduce seq_hex_dump() helper Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 1/6] seq_file: provide an analogue of print_hex_dump() Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 2/6] crypto: qat - use seq_hex_dump() to dump buffers Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 3/6] parisc: " Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 4/6] [S390] zcrypt: " Andy Shevchenko
2015-07-07 17:04 ` [PATCH v5 5/6] kmemleak: " Andy Shevchenko
2015-07-08 9:20 ` Catalin Marinas
2015-07-07 17:04 ` [PATCH v5 6/6] wil6210: " Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).