mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/3] Add pr_memory_display
Date: Mon,  3 Dec 2018 08:37:59 +0100	[thread overview]
Message-ID: <20181203073759.7864-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20181203073759.7864-1-s.hauer@pengutronix.de>

pr_memory_display is a memory_display variant that takes a MSG_*
loglevel priority with which the hexdump is printed. Like the
normal pr_* function this is optimized out when the priority is
below the compile time priority.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/memory_display.c | 37 ++++++++++++++++++++++++++++++++-----
 include/printk.h        |  8 ++++++++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/common/memory_display.c b/common/memory_display.c
index 03d418b33b..cd0eadf88d 100644
--- a/common/memory_display.c
+++ b/common/memory_display.c
@@ -4,11 +4,21 @@
 
 #define DISP_LINE_LEN	16
 
-int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int swab)
+
+int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbytes,
+			int size, int swab, const char *fmt, ...)
 {
 	unsigned long linebytes, i;
 	unsigned char *cp;
 	unsigned char line[sizeof("00000000: 0000 0000 0000 0000  0000 0000 0000 0000            ................")];
+	struct va_format vaf;
+	int ret;
+	va_list args;
+
+	va_start(args, fmt);
+
+	vaf.fmt = fmt;
+	vaf.va = &args;
 
 	/* Print the lines.
 	 *
@@ -98,11 +108,28 @@ int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int
 			cp++;
 		}
 
-		printf("%s\n", line);
+		if (level >= MSG_EMERG)
+			pr_print(level, "%pV%s\n", &vaf, line);
+		else
+			printf("%s\n", line);
+
 		nbytes -= linebytes;
-		if (ctrlc())
-			return -EINTR;
+		if (ctrlc()) {
+			ret = -EINTR;
+			goto out;
+		}
+
 	} while (nbytes > 0);
 
-	return 0;
+	va_end(args);
+	ret = 0;
+out:
+
+	return ret;
 }
+
+int memory_display(const void *addr, loff_t offs, unsigned nbytes,
+		   int size, int swab)
+{
+	return pr_memory_display(-1, addr, offs, nbytes, size, swab);
+}
\ No newline at end of file
diff --git a/include/printk.h b/include/printk.h
index 4843dadd76..aaad07552e 100644
--- a/include/printk.h
+++ b/include/printk.h
@@ -105,6 +105,14 @@ static inline int pr_print(int level, const char *format, ...)
 
 int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size,
 		   int swab);
+int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbytes,
+			int size, int swab, const char *format, ...);
+
+#define pr_memory_display(level, addr, offs, nbytes, size, swab) \
+	({	\
+		(level) <= LOGLEVEL ? __pr_memory_display((level), (addr), \
+				(offs), (nbytes), (size), (swab), pr_fmt("")) : 0; \
+	 })
 
 #define DUMP_PREFIX_OFFSET 0
 static inline void print_hex_dump(const char *level, const char *prefix_str,
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2018-12-03  7:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-03  7:37 [PATCH 1/3] memory_display: Print whole line at once Sascha Hauer
2018-12-03  7:37 ` [PATCH 2/3] memory_display: move prototype to include/printk.h Sascha Hauer
2018-12-03  7:37 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181203073759.7864-3-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox