helpers: Add an integer division helper that rounds up

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
This commit is contained in:
Philipp Zabel 2023-07-14 12:43:59 +02:00 committed by Marius Vlad
parent 617bb9afc9
commit b3d94c9843
1 changed files with 10 additions and 0 deletions

View File

@ -95,6 +95,16 @@ do { \
#define CLIP(c, x, y) MIN(MAX(c, x), y)
#endif
/**
* Divides two integers, rounding up.
*
* @param n the numerator to divide.
* @param d the denominator to divide by.
* @return the rounded up result of the division n / d.
*/
#define DIV_ROUND_UP(n, d) \
({ typeof(d) tmp = (d); ((n) + tmp - 1) / tmp; })
/**
* Returns a pointer to the containing struct of a given member item.
*