]> git.openfabrics.org - ~aditr/compat.git/commitdiff
compat: add round_down
authorHauke Mehrtens <hauke@hauke-m.de>
Thu, 11 Aug 2011 11:02:37 +0000 (13:02 +0200)
committerLuis R. Rodriguez <mcgrof@qca.qualcomm.com>
Fri, 12 Aug 2011 00:57:11 +0000 (17:57 -0700)
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
include/linux/compat-2.6.34.h

index bada7005bb097947f4de1d0b231ac3060eeabaea..7bda52b78aba7d92f61d6cd71c26194aba70c028 100644 (file)
@@ -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 */