efi_loader: correctly handle mixed hashes and signatures in db
[platform/kernel/u-boot.git] / lib / hexdump.c
index a76ea70..149c93e 100644 (file)
@@ -16,6 +16,8 @@
 #include <linux/log2.h>
 #include <asm/unaligned.h>
 
+#define MAX_LINE_LENGTH_BYTES  64
+
 const char hex_asc[] = "0123456789abcdef";
 const char hex_asc_upper[] = "0123456789ABCDEF";
 
@@ -30,8 +32,10 @@ int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize,
        int ascii_column;
        int ret;
 
-       if (rowsize != 16 && rowsize != 32)
+       if (!rowsize)
                rowsize = 16;
+       else
+               rowsize = min(rowsize, MAX_LINE_LENGTH_BYTES);
 
        if (len > rowsize)              /* limit to one line at a time */
                len = rowsize;
@@ -121,15 +125,17 @@ overflow1:
        return ascii ? ascii_column + len : (groupsize * 2 + 1) * ngroups - 1;
 }
 
-void print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
-                   int groupsize, const void *buf, size_t len, bool ascii)
+int print_hex_dump(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;
-       char linebuf[32 * 3 + 2 + 32 + 1];
+       char linebuf[MAX_LINE_LENGTH_BYTES * 3 + 2 + MAX_LINE_LENGTH_BYTES + 1];
 
-       if (rowsize != 16 && rowsize != 32)
+       if (!rowsize)
                rowsize = 16;
+       else
+               rowsize = min(rowsize, MAX_LINE_LENGTH_BYTES);
 
        for (i = 0; i < len; i += rowsize) {
                linelen = min(remaining, rowsize);
@@ -151,7 +157,11 @@ void print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
                        printf("%s%s\n", prefix_str, linebuf);
                        break;
                }
+               if (!IS_ENABLED(CONFIG_SPL_BUILD) && ctrlc())
+                       return -EINTR;
        }
+
+       return 0;
 }
 
 void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
@@ -164,9 +174,10 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  * Some code in U-Boot copy-pasted from Linux kernel uses both
  * functions below so to keep stuff compilable we keep these stubs here.
  */
-void print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
-                   int groupsize, const void *buf, size_t len, bool ascii)
+int print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
+                  int groupsize, const void *buf, size_t len, bool ascii)
 {
+       return -ENOSYS;
 }
 
 void print_hex_dump_bytes(const char *prefix_str, int prefix_type,