Skip to content
Permalink
Browse files

ROUND_UP/DOWN macros: cast the entire align argument

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 21, 2019
1 parent df0b49c commit e85b9315c28a9e13d899af7af78b81d8c98ade5c
Showing with 4 additions and 3 deletions.
  1. +4 −3 include/misc/util.h
@@ -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))

0 comments on commit e85b931

Please sign in to comment.
You can’t perform that action at this time.