Skip to content

Commit

Permalink
ROUND_UP/DOWN macros: cast the entire align argument
Browse files Browse the repository at this point in the history
Enclose the align argument in parents to make sure the cast applies to
the whole expression when expanded. This is especially important if the
argument contains a ternary operator.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
  • Loading branch information
Nicolas Pitre authored and nashif committed May 30, 2019
1 parent df0b49c commit e85b931
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/misc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ constexpr size_t ARRAY_SIZE(T(&)[N]) { return N; }

/* round "x" up/down to next multiple of "align" (which must be a power of 2) */
#define ROUND_UP(x, align) \
(((unsigned long)(x) + ((unsigned long)align - 1)) & \
~((unsigned long)align - 1))
#define ROUND_DOWN(x, align) ((unsigned long)(x) & ~((unsigned long)align - 1))
(((unsigned long)(x) + ((unsigned long)(align) - 1)) & \
~((unsigned long)(align) - 1))
#define ROUND_DOWN(x, align) \
((unsigned long)(x) & ~((unsigned long)(align) - 1))

#define ceiling_fraction(numerator, divider) \
(((numerator) + ((divider) - 1)) / (divider))
Expand Down

0 comments on commit e85b931

Please sign in to comment.