<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 08/14/2018 04:45 PM, Colin King
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:20180814084526.18006-1-colin.king@canonical.com">
      <pre wrap="">From: Colin Ian King <a class="moz-txt-link-rfc2396E" href="mailto:colin.king@canonical.com"><colin.king@canonical.com></a>

These are general purpose enough helper macros to be added to
fwts.h.  Prefix them with FWTS_ and update fwts_coreboot_cbmem.c
to use these instead.

Signed-off-by: Colin Ian King <a class="moz-txt-link-rfc2396E" href="mailto:colin.king@canonical.com"><colin.king@canonical.com></a>
---
 src/lib/include/fwts.h            |  7 +++++++
 src/lib/src/fwts_coreboot_cbmem.c | 11 ++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/lib/include/fwts.h b/src/lib/include/fwts.h
index a9115da7..62834ec3 100644
--- a/src/lib/include/fwts.h
+++ b/src/lib/include/fwts.h
@@ -23,6 +23,13 @@
 
 #include "config.h"
 
+/*
+ *  Helper macros, minimum, maximum and array size
+ */
+#define FWTS_MIN(a, b)         ((a) < (b) ? (a) : (b))
+#define FWTS_MAX(a, b)         ((a) > (b) ? (a) : (b))
+#define FWTS_ARRAY_SIZE(x)     (sizeof(x) / sizeof((x)[0]))
+
 /*
  *  convert version to a large integer for easier comparison
  */
diff --git a/src/lib/src/fwts_coreboot_cbmem.c b/src/lib/src/fwts_coreboot_cbmem.c
index 3add0871..214fa55e 100644
--- a/src/lib/src/fwts_coreboot_cbmem.c
+++ b/src/lib/src/fwts_coreboot_cbmem.c
@@ -38,9 +38,6 @@
 #define LB_TAG_CBMEM_CONSOLE   0x0017
 #define LB_TAG_FORWARD         0x0011
 
-#define MIN(a,b) ((a)<(b) ? (a):(b))
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
 struct lb_record {
         uint32_t tag;           /* tag ID */
         uint32_t size;          /* size of record (in bytes) */
@@ -277,10 +274,10 @@ static ssize_t memconsole_coreboot_read(struct cbmem_console *con, char *buf, si
                seg[0] = (struct seg){.phys = cursor, .len = count - cursor};
                seg[1] = (struct seg){.phys = 0, .len = cursor};
        } else {
-               seg[0] = (struct seg){.phys = 0, .len = MIN(cursor, count)};
+               seg[0] = (struct seg){.phys = 0, .len = FWTS_MIN(cursor, count)};
        }
 
-       for (i = 0; i < ARRAY_SIZE(seg) && count > done; i++) {
+       for (i = 0; i < FWTS_ARRAY_SIZE(seg) && count > done; i++) {
                done += memory_read_from_buffer(buf + done, count - done, &pos,
                        con->body + seg[i].phys, seg[i].len);
                pos -= seg[i].len;
@@ -300,11 +297,11 @@ char *fwts_coreboot_cbmem_console_dump(void)
        ssize_t count;
 
        /* Find and parse coreboot table */
-       for (j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) {
+       for (j = 0; j < FWTS_ARRAY_SIZE(possible_base_addresses); j++) {
                if (!parse_cbtable(possible_base_addresses[j], 0, &cbmem_console_addr))
                        break;
        }
-       if (j == ARRAY_SIZE(possible_base_addresses))
+       if (j == FWTS_ARRAY_SIZE(possible_base_addresses))
                return NULL;
 
        console_p = map_memory(cbmem_console_addr, sizeof(*console_p));
</pre>
    </blockquote>
    <br>
    Acked-by: Ivan Hu <a class="moz-txt-link-rfc2396E"
      href="mailto:ivan.hu@canonical.com"><ivan.hu@canonical.com></a>
  </body>
</html>