From fe423782023ee165497e4a8f53100554d4e35b18 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 6 Apr 2023 18:19:03 +0200 Subject: [PATCH] sys: util: force Zephyr BIT/MIN/MAX/CLAMP definitions We've been guarding the definition of BIT/MIN/MAX/CLAMP macros as they are commonly found in other projects. This is dangerous, because depending on the order of includes, Zephyr code could end up using macros defined by other projects (e.g. via HALs). The current #ifndef _protection_ goes against the recently established guidelines in #51963, so let's remove it. Ref. https://docs.zephyrproject.org/latest/contribute/coding_guidelines/ index.html#rule-a-3-macro-name-collisions Signed-off-by: Gerard Marull-Paretas --- include/zephyr/sys/util.h | 6 ------ include/zephyr/sys/util_macro.h | 2 -- 2 files changed, 8 deletions(-) diff --git a/include/zephyr/sys/util.h b/include/zephyr/sys/util.h index 2608fdb6d5f9543..d20a254cd0de162 100644 --- a/include/zephyr/sys/util.h +++ b/include/zephyr/sys/util.h @@ -250,7 +250,6 @@ extern "C" { #define ceiling_fraction(numerator, divider) \ (((numerator) + ((divider) - 1)) / (divider)) -#ifndef MAX /** * @brief Obtain the maximum of two values. * @@ -263,9 +262,7 @@ extern "C" { * @returns Maximum value of @p a and @p b. */ #define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif -#ifndef MIN /** * @brief Obtain the minimum of two values. * @@ -278,9 +275,7 @@ extern "C" { * @returns Minimum value of @p a and @p b. */ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif -#ifndef CLAMP /** * @brief Clamp a value to a given range. * @@ -294,7 +289,6 @@ extern "C" { * @returns Clamped value. */ #define CLAMP(val, low, high) (((val) <= (low)) ? (low) : MIN(val, high)) -#endif /** * @brief Checks if a value is within range. diff --git a/include/zephyr/sys/util_macro.h b/include/zephyr/sys/util_macro.h index 3e1419f3ef0cd0b..3dfcec7b7877dbe 100644 --- a/include/zephyr/sys/util_macro.h +++ b/include/zephyr/sys/util_macro.h @@ -33,7 +33,6 @@ extern "C" { */ #include -#ifndef BIT #if defined(_ASMLANGUAGE) #define BIT(n) (1 << (n)) #else @@ -43,7 +42,6 @@ extern "C" { */ #define BIT(n) (1UL << (n)) #endif -#endif /** @brief 64-bit unsigned integer with bit position @p _n set. */ #define BIT64(_n) (1ULL << (_n))