Skip to content

Commit 2d1cfe8

Browse files
fsammoura1980cfriedt
authored andcommitted
include: util: Applied clang-formatting
This commit applies clang-format to file include/zephyr/sys/util.h to align them with the latest Zephyr coding style guidelines. Signed-off-by: Firas Sammoura <[email protected]>
1 parent d906376 commit 2d1cfe8

File tree

1 file changed

+36
-42
lines changed

1 file changed

+36
-42
lines changed

include/zephyr/sys/util.h

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ extern "C" {
4646
*/
4747

4848
/** @brief Cast @p x, a pointer, to an unsigned integer. */
49-
#define POINTER_TO_UINT(x) ((uintptr_t) (x))
49+
#define POINTER_TO_UINT(x) ((uintptr_t)(x))
5050
/** @brief Cast @p x, an unsigned integer, to a <tt>void*</tt>. */
51-
#define UINT_TO_POINTER(x) ((void *) (uintptr_t) (x))
51+
#define UINT_TO_POINTER(x) ((void *)(uintptr_t)(x))
5252
/** @brief Cast @p x, a pointer, to a signed integer. */
53-
#define POINTER_TO_INT(x) ((intptr_t) (x))
53+
#define POINTER_TO_INT(x) ((intptr_t)(x))
5454
/** @brief Cast @p x, a signed integer, to a <tt>void*</tt>. */
55-
#define INT_TO_POINTER(x) ((void *) (intptr_t) (x))
55+
#define INT_TO_POINTER(x) ((void *)(intptr_t)(x))
5656

5757
#if !(defined(__CHAR_BIT__) && defined(__SIZEOF_LONG__) && defined(__SIZEOF_LONG_LONG__))
58-
# error Missing required predefined macros for BITS_PER_LONG calculation
58+
#error Missing required predefined macros for BITS_PER_LONG calculation
5959
#endif
6060

6161
/** Number of bits in a byte. */
@@ -68,27 +68,25 @@ extern "C" {
6868
#define NIBBLES_PER_BYTE (BITS_PER_BYTE / BITS_PER_NIBBLE)
6969

7070
/** Number of bits in a long int. */
71-
#define BITS_PER_LONG (__CHAR_BIT__ * __SIZEOF_LONG__)
71+
#define BITS_PER_LONG (__CHAR_BIT__ * __SIZEOF_LONG__)
7272

7373
/** Number of bits in a long long int. */
74-
#define BITS_PER_LONG_LONG (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
74+
#define BITS_PER_LONG_LONG (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
7575

7676
/**
7777
* @brief Create a contiguous bitmask starting at bit position @p l
7878
* and ending at position @p h.
7979
*/
80-
#define GENMASK(h, l) \
81-
(((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
80+
#define GENMASK(h, l) (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
8281

8382
/**
8483
* @brief Create a contiguous 64-bit bitmask starting at bit position @p l
8584
* and ending at position @p h.
8685
*/
87-
#define GENMASK64(h, l) \
88-
(((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
86+
#define GENMASK64(h, l) (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
8987

9088
/** @brief 0 if @p cond is true-ish; causes a compile error otherwise. */
91-
#define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - (2 * !(cond))]) - 1)
89+
#define ZERO_OR_COMPILE_ERROR(cond) ((int)sizeof(char[1 - (2 * !(cond))]) - 1)
9290

9391
#if defined(__cplusplus)
9492

@@ -104,10 +102,9 @@ extern "C" {
104102
*
105103
* This macro is available only from C, not C++.
106104
*/
107-
#define IS_ARRAY(array) \
108-
ZERO_OR_COMPILE_ERROR( \
109-
!__builtin_types_compatible_p(__typeof__(array), \
110-
__typeof__(&(array)[0])))
105+
#define IS_ARRAY(array) \
106+
ZERO_OR_COMPILE_ERROR( \
107+
!__builtin_types_compatible_p(__typeof__(array), __typeof__(&(array)[0])))
111108

112109
/**
113110
* @brief Number of elements in the given @p array
@@ -118,8 +115,7 @@ extern "C" {
118115
*
119116
* In C, passing a pointer as @p array causes a compile error.
120117
*/
121-
#define ARRAY_SIZE(array) \
122-
((size_t) (IS_ARRAY(array) + (sizeof(array) / sizeof((array)[0]))))
118+
#define ARRAY_SIZE(array) ((size_t)(IS_ARRAY(array) + (sizeof(array) / sizeof((array)[0]))))
123119

124120
#endif /* __cplusplus */
125121

@@ -140,10 +136,11 @@ extern "C" {
140136
* It is specially useful for cases where flexible arrays are
141137
* used in unions or are not the last element in the struct.
142138
*/
143-
#define FLEXIBLE_ARRAY_DECLARE(type, name) \
144-
struct { \
145-
struct { } __unused_##name; \
146-
type name[]; \
139+
#define FLEXIBLE_ARRAY_DECLARE(type, name) \
140+
struct { \
141+
struct { \
142+
} __unused_##name; \
143+
type name[]; \
147144
}
148145

149146
/**
@@ -161,7 +158,7 @@ extern "C" {
161158
* @return 1 if @p ptr is part of @p array, 0 otherwise
162159
*/
163160
#define IS_ARRAY_ELEMENT(array, ptr) \
164-
((ptr) && POINTER_TO_UINT(array) <= POINTER_TO_UINT(ptr) && \
161+
((ptr) && POINTER_TO_UINT(array) <= POINTER_TO_UINT(ptr) && \
165162
POINTER_TO_UINT(ptr) < POINTER_TO_UINT(&(array)[ARRAY_SIZE(array)]) && \
166163
(POINTER_TO_UINT(ptr) - POINTER_TO_UINT(array)) % sizeof((array)[0]) == 0)
167164

@@ -253,9 +250,8 @@ extern "C" {
253250
* @brief Validate CONTAINER_OF parameters, only applies to C mode.
254251
*/
255252
#ifndef __cplusplus
256-
#define CONTAINER_OF_VALIDATE(ptr, type, field) \
257-
BUILD_ASSERT(SAME_TYPE(*(ptr), ((type *)0)->field) || \
258-
SAME_TYPE(*(ptr), void), \
253+
#define CONTAINER_OF_VALIDATE(ptr, type, field) \
254+
BUILD_ASSERT(SAME_TYPE(*(ptr), ((type *)0)->field) || SAME_TYPE(*(ptr), void), \
259255
"pointer type mismatch in CONTAINER_OF");
260256
#else
261257
#define CONTAINER_OF_VALIDATE(ptr, type, field)
@@ -282,10 +278,10 @@ extern "C" {
282278
* @param field the name of the field within the struct @p ptr points to
283279
* @return a pointer to the structure that contains @p ptr
284280
*/
285-
#define CONTAINER_OF(ptr, type, field) \
286-
({ \
287-
CONTAINER_OF_VALIDATE(ptr, type, field) \
288-
((type *)(((char *)(ptr)) - offsetof(type, field))); \
281+
#define CONTAINER_OF(ptr, type, field) \
282+
({ \
283+
CONTAINER_OF_VALIDATE(ptr, type, field) \
284+
((type *)(((char *)(ptr)) - offsetof(type, field))); \
289285
})
290286

291287
/**
@@ -309,8 +305,7 @@ extern "C" {
309305
*
310306
* @return Concatenated token.
311307
*/
312-
#define CONCAT(...) \
313-
UTIL_CAT(_CONCAT_, NUM_VA_ARGS_LESS_1(__VA_ARGS__))(__VA_ARGS__)
308+
#define CONCAT(...) UTIL_CAT(_CONCAT_, NUM_VA_ARGS_LESS_1(__VA_ARGS__))(__VA_ARGS__)
314309

315310
/**
316311
* @brief Check if @p ptr is aligned to @p align alignment
@@ -320,14 +315,14 @@ extern "C" {
320315
/**
321316
* @brief Value of @p x rounded up to the next multiple of @p align.
322317
*/
323-
#define ROUND_UP(x, align) \
324-
((((unsigned long)(x) + ((unsigned long)(align) - 1)) / \
325-
(unsigned long)(align)) * (unsigned long)(align))
318+
#define ROUND_UP(x, align) \
319+
((((unsigned long)(x) + ((unsigned long)(align) - 1)) / (unsigned long)(align)) * \
320+
(unsigned long)(align))
326321

327322
/**
328323
* @brief Value of @p x rounded down to the previous multiple of @p align.
329324
*/
330-
#define ROUND_DOWN(x, align) \
325+
#define ROUND_DOWN(x, align) \
331326
(((unsigned long)(x) / (unsigned long)(align)) * (unsigned long)(align))
332327

333328
/** @brief Value of @p x rounded up to the next word boundary. */
@@ -869,7 +864,7 @@ static inline int64_t sign_extend_64(uint64_t value, uint8_t index)
869864

870865
#define __z_log2d(x) (32 - __builtin_clz(x) - 1)
871866
#define __z_log2q(x) (64 - __builtin_clzll(x) - 1)
872-
#define __z_log2(x) (sizeof(__typeof__(x)) > 4 ? __z_log2q(x) : __z_log2d(x))
867+
#define __z_log2(x) (sizeof(__typeof__(x)) > 4 ? __z_log2q(x) : __z_log2d(x))
873868

874869
/**
875870
* @brief Compute log2(x)
@@ -893,7 +888,7 @@ static inline int64_t sign_extend_64(uint64_t value, uint8_t index)
893888
*
894889
* @return ceil(log2(x)) when 1 <= x <= max(type(x)), 0 when x < 1
895890
*/
896-
#define LOG2CEIL(x) ((x) <= 1 ? 0 : __z_log2((x)-1) + 1)
891+
#define LOG2CEIL(x) ((x) <= 1 ? 0 : __z_log2((x) - 1) + 1)
897892

898893
/**
899894
* @brief Compute next highest power of two
@@ -907,7 +902,7 @@ static inline int64_t sign_extend_64(uint64_t value, uint8_t index)
907902
*
908903
* @return 2^ceil(log2(x)) or 0 if 2^ceil(log2(x)) would saturate 64-bits
909904
*/
910-
#define NHPOT(x) ((x) < 1 ? 1 : ((x) > (1ULL<<63) ? 0 : 1ULL << LOG2CEIL(x)))
905+
#define NHPOT(x) ((x) < 1 ? 1 : ((x) > (1ULL << 63) ? 0 : 1ULL << LOG2CEIL(x)))
911906

912907
/**
913908
* @brief Determine if a buffer exceeds highest address
@@ -921,9 +916,8 @@ static inline int64_t sign_extend_64(uint64_t value, uint8_t index)
921916
*
922917
* @return true if pointer overflow detected, false otherwise
923918
*/
924-
#define Z_DETECT_POINTER_OVERFLOW(addr, buflen) \
925-
(((buflen) != 0) && \
926-
((UINTPTR_MAX - (uintptr_t)(addr)) <= ((uintptr_t)((buflen) - 1))))
919+
#define Z_DETECT_POINTER_OVERFLOW(addr, buflen) \
920+
(((buflen) != 0) && ((UINTPTR_MAX - (uintptr_t)(addr)) <= ((uintptr_t)((buflen) - 1))))
927921

928922
/**
929923
* @brief XOR n bytes

0 commit comments

Comments
 (0)