scst: Add a round_up() backport

A call to round_up() was introduced in r7854 / commit 434207ab53.


git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8061 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2019-03-20 02:01:13 +00:00
parent 9030abc19d
commit eb83c6971b

View File

@@ -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