[PATCH 1/2] Add MIN, MAX and ARRAY_SIZE macros to fwts.h
Colin King
colin.king at canonical.com
Tue Aug 14 08:45:25 UTC 2018
From: Colin Ian King <colin.king at canonical.com>
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 <colin.king at canonical.com>
---
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));
--
2.17.1
More information about the fwts-devel
mailing list