[coreboot-gerrit] Patch set updated for coreboot: 97856d8 util/cbmem: Don't output trailing garbage for cbmemc

Vladimir Serbinenko (phcoder@gmail.com) gerrit at coreboot.org
Sat Mar 30 16:40:44 CET 2013


Vladimir Serbinenko (phcoder at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/2991

-gerrit

commit 97856d861d33fe922ce654e36930ca878b9d26b7
Author: Vladimir Serbinenko <phcoder at gmail.com>
Date:   Sat Mar 30 12:15:12 2013 +0100

    util/cbmem: Don't output trailing garbage for cbmemc
    
    Current code output the whole cbmemc buffer even if only part of
    it is really used. Fix it to output only really used part and notify
    if the buffer was too small for the required data.
    
    Change-Id: I68c1970cf84d49b2d7d6007dae0679d7a7a0cb99
    Signed-off-by: Vladimir Serbinenko <phcoder at gmail.com>
---
 util/cbmem/cbmem.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c
index bc6bd6b..09a073e 100644
--- a/util/cbmem/cbmem.c
+++ b/util/cbmem/cbmem.c
@@ -308,12 +308,21 @@ static void dump_timestamps(void)
 	unmap_memory();
 }
 
+static const char *future_ngettext (const char *sing, const char *plural,
+	unsigned long int n)
+{
+	if (n == 1)
+		return sing;
+	return plural;
+}
+
 /* dump the cbmem console */
 static void dump_console(void)
 {
 	void *console_p;
 	char *console_c;
 	uint32_t size;
+	uint32_t cursor;
 
 	if (console.tag != LB_TAG_CBMEM_CONSOLE) {
 		fprintf(stderr, "No console found in coreboot table.\n");
@@ -328,6 +337,12 @@ static void dump_console(void)
 	 * Hence we have to add 8 to get to the actual console string.
 	 */
 	size = *(uint32_t *)console_p;
+	cursor = *(uint32_t *) (console_p + 4);
+	/* Cursor continues to go on even after no more data fits in
+	   the buffer but the data is dropped in this case.
+	 */
+	if (size > cursor)
+		size = cursor;
 	console_c = malloc(size + 1);
 	if (!console_c) {
 		fprintf(stderr, "Not enough memory for console.\n");
@@ -337,7 +352,11 @@ static void dump_console(void)
 	memcpy(console_c, console_p + 8, size);
 	console_c[size] = 0;
 
-	printf("%s", console_c);
+	printf("%s\n", console_c);
+	if (size < cursor)
+		printf (future_ngettext ("1 byte lost\n" :
+					 "%d bytes lost\n", cursor - size),
+			cursor - size);
 
 	free(console_c);
 



More information about the coreboot-gerrit mailing list