From eb83c6971b8b80fb6cbd3fe1248da63e9c21af68 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 20 Mar 2019 02:01:13 +0000 Subject: [PATCH] scst: Add a round_up() backport A call to round_up() was introduced in r7854 / commit 434207ab5387. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8061 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/scst/include/backport.h b/scst/include/backport.h index b938f89b8..f4f6ce8fa 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -510,6 +510,35 @@ typedef _Bool bool; extern int hex_to_bin(char ch); #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) && !defined(RHEL_MAJOR) +/* See also commit 9b3be9f99203 ("Move round_up/down to kernel.h") # v2.6.34 */ +/* + * This looks more complex than it should be. But we need to + * get the type for the ~ right in round_down (it needs to be + * as wide as the result!), and we want to evaluate the macro + * arguments just once each. + */ +#define __round_mask(x, y) ((__typeof__(x))((y)-1)) +/** + * round_up - round up to next specified power of 2 + * @x: the value to round + * @y: multiple to round up to (must be a power of 2) + * + * Rounds @x up to next multiple of @y (which must be a power of 2). + * To perform arbitrary rounding up, use roundup() below. + */ +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) +/** + * round_down - round down to next specified power of 2 + * @x: the value to round + * @y: multiple to round down to (must be a power of 2) + * + * Rounds @x down to next multiple of @y (which must be a power of 2). + * To perform arbitrary rounding down, use rounddown() below. + */ +#define round_down(x, y) ((x) & ~__round_mask(x, y)) +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) /* * See also "lib: hex2bin converts ascii hexadecimal string to binary" (commit