From: Hauke Mehrtens Date: Thu, 11 Aug 2011 11:02:37 +0000 (+0200) Subject: compat: add round_down X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=c2544bbb8399893f2a96800f132ab9b5ed76a39c;p=~aditr%2Fcompat.git compat: add round_down Signed-off-by: Hauke Mehrtens --- diff --git a/include/linux/compat-2.6.34.h b/include/linux/compat-2.6.34.h index bada700..7bda52b 100644 --- a/include/linux/compat-2.6.34.h +++ b/include/linux/compat-2.6.34.h @@ -252,6 +252,16 @@ static inline int usb_disable_autosuspend(struct usb_device *udev) #define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */ +/* + * 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)) +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) +#define round_down(x, y) ((x) & ~__round_mask(x, y)) + #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)) */ #endif /* LINUX_26_34_COMPAT_H */