Hello Alex Levin,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/42234
to review the following change.
Change subject: libpayload: Fix potential compilation issues ......................................................................
libpayload: Fix potential compilation issues
The include chain can define one of the marcros (BIT, MIN, MAX ar all very common) and this will cause a compilation issue. Wrapping with ifndef to protect from that.
Change-Id: I1e1c1f8e75b752bc3d78e0c843866d0144b82b2a Signed-off-by: Alex Levin levinale@chromium.org --- M payloads/libpayload/include/libpayload.h 1 file changed, 27 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/34/42234/1
diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h index 25080d8..5b9f052 100644 --- a/payloads/libpayload/include/libpayload.h +++ b/payloads/libpayload/include/libpayload.h @@ -66,31 +66,55 @@ #include <archive.h>
/* Double-evaluation unsafe min/max, for bitfields and outside of functions */ +#ifndef __CMP_UNSAFE #define __CMP_UNSAFE(a, b, op) ((a) op (b) ? (a) : (b)) -#define MIN_UNSAFE(a, b) __CMP_UNSAFE(a, b, <) -#define MAX_UNSAFE(a, b) __CMP_UNSAFE(a, b, >) +#endif
+#ifndef MIN_UNSAFE +#define MIN_UNSAFE(a, b) __CMP_UNSAFE(a, b, <) +#endif + +#ifndef MAX_UNSAFE +#define MAX_UNSAFE(a, b) __CMP_UNSAFE(a, b, >) +#endif + +#ifndef __CMP_SAFE #define __CMP_SAFE(a, b, op, var_a, var_b) ({ \ __TYPEOF_UNLESS_CONST(a, b) var_a = (a); \ __TYPEOF_UNLESS_CONST(b, a) var_b = (b); \ var_a op var_b ? var_a : var_b; \ }) +#endif
+#ifndef __CMP #define __CMP(a, b, op) __builtin_choose_expr( \ __builtin_constant_p(a) && __builtin_constant_p(b), \ __CMP_UNSAFE(a, b, op), __CMP_SAFE(a, b, op, __TMPNAME, __TMPNAME)) +#endif
+#ifndef MIN #define MIN(a, b) __CMP(a, b, <) +#endif + +#ifndef MAX #define MAX(a, b) __CMP(a, b, >) +#endif
+#ifndef ARRAY_SIZE #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) -#define BIT(x) (1ul << (x)) +#endif
+#ifndef BIT +#define BIT(x) (1ul << (x)) +#endif + +#ifndef DIV_ROUND_UP #define DIV_ROUND_UP(x, y) ({ \ typeof(x) _div_local_x = (x); \ typeof(y) _div_local_y = (y); \ (_div_local_x + _div_local_y - 1) / _div_local_y; \ }) +#endif
static inline u32 div_round_up(u32 n, u32 d) { return (n + d - 1) / d; }