[PATCH v5 13/14] hexdump: provide support for dev_print_hex_dump()

Oleksij Rempel o.rempel at pengutronix.de
Wed Apr 13 01:22:04 PDT 2022


In some cases we need to know the interface name of dumped hex. So,
provide optional device_d pointer and use it to get device name.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 include/printk.h | 14 +++++++++++---
 lib/hexdump.c    | 22 +++++++++++++++-------
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/include/printk.h b/include/printk.h
index 046b456a9d..8de8202af9 100644
--- a/include/printk.h
+++ b/include/printk.h
@@ -4,6 +4,8 @@
 
 #include <linux/types.h>
 
+struct device_d;
+
 #define KERN_EMERG      ""   /* system is unusable                   */
 #define KERN_ALERT      ""   /* action must be taken immediately     */
 #define KERN_CRIT       ""   /* critical conditions                  */
@@ -45,9 +47,15 @@ enum {
 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
 			      int groupsize, char *linebuf, size_t linebuflen,
 			      bool ascii);
-extern void print_hex_dump(const char *level, const char *prefix_str,
-			   int prefix_type, int rowsize, int groupsize,
-			   const void *buf, size_t len, bool ascii);
+extern void dev_print_hex_dump(struct device_d *dev, const char *level,
+			       const char *prefix_str, int prefix_type,
+			       int rowsize, int groupsize, const void *buf,
+			       size_t len, bool ascii);
+
+#define print_hex_dump(level, prefix_str, prefix_type, rowsize,		       \
+			     groupsize, buf, len, ascii)		       \
+	dev_print_hex_dump(NULL, level, prefix_str, prefix_type, rowsize,      \
+		       groupsize, buf, len, ascii)
 
 #ifdef CONFIG_ARCH_HAS_STACK_DUMP
 void dump_stack(void);
diff --git a/lib/hexdump.c b/lib/hexdump.c
index fb80ef9724..61bbb10129 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <driver.h>
 #include <linux/types.h>
 #include <linux/ctype.h>
 #include <linux/log2.h>
@@ -235,13 +236,16 @@ EXPORT_SYMBOL(hex_dump_to_buffer);
  * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode:
  * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c  pqrstuvwxyz{|}~.
  */
-void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
-		    int rowsize, int groupsize,
-		    const void *buf, size_t len, bool ascii)
+void dev_print_hex_dump(struct device_d *dev, const char *level,
+			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;
 	unsigned char linebuf[32 * 3 + 2 + 32 + 1];
+	char *name;
+
+	name = basprintf("%s%s", dev ? dev_name(dev) : "", dev ? ": " : "");
 
 	if (rowsize != 16 && rowsize != 32)
 		rowsize = 16;
@@ -255,16 +259,20 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
 
 		switch (prefix_type) {
 		case DUMP_PREFIX_ADDRESS:
-			printk("%s%s%p: %s\n",
-			       level, prefix_str, ptr + i, linebuf);
+			printk("%s%s%s%p: %s\n", level, name, prefix_str,
+			       ptr + i, linebuf);
 			break;
 		case DUMP_PREFIX_OFFSET:
-			printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
+			printk("%s%s%s%.8x: %s\n", level, name, prefix_str,
+			       i, linebuf);
 			break;
 		default:
-			printk("%s%s%s\n", level, prefix_str, linebuf);
+			printk("%s%s%s%s\n", level, name, prefix_str,
+			       linebuf);
 			break;
 		}
 	}
+
+	free(name);
 }
 EXPORT_SYMBOL(print_hex_dump);
-- 
2.30.2




More information about the barebox mailing list