diff mbox series

[1/2] Add MIN, MAX and ARRAY_SIZE macros to fwts.h

Message ID 20180814084526.18006-1-colin.king@canonical.com
State Accepted
Headers show
Series [1/2] Add MIN, MAX and ARRAY_SIZE macros to fwts.h | expand

Commit Message

Colin Ian King Aug. 14, 2018, 8:45 a.m. UTC
From: Colin Ian King <colin.king@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@canonical.com>
---
 src/lib/include/fwts.h            |  7 +++++++
 src/lib/src/fwts_coreboot_cbmem.c | 11 ++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

Comments

Alex Hung Aug. 14, 2018, 7:25 p.m. UTC | #1
On 2018-08-14 01:45 AM, Colin King wrote:
> From: Colin Ian King <colin.king@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@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));
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Aug. 16, 2018, 9:01 a.m. UTC | #2
On 08/14/2018 04:45 PM, Colin King wrote:
> From: Colin Ian King <colin.king@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@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));

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

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));