[dm-devel] /usr/src/linux/drivers/md/bitmap.c: strange rounding lines 855-875
Ulrich Windl
Ulrich.Windl at rz.uni-regensburg.de
Thu Oct 21 14:19:27 UTC 2010
Hi,
I just found this strange rounding code in /usr/src/linux/drivers/md/bitmap.c:
-----snip-------
/* We need 4 bits per page, rounded up to a multiple of sizeof(unsigned
long) */
bitmap->filemap_attr = kzalloc(
(((num_pages*4/8)+sizeof(unsigned long))
/sizeof(unsigned long))
*sizeof(unsigned long),
GFP_KERNEL);
---------snip-----
IMHO, this is not rounding, it's just adding one extra "sizeof(unsigned long)":
Instead of using the pattern "((a + b) / b) * b" == (a/b + 1) * b == a + b the pattern "((a + b - 1) / b) * b" should be used. Even preferrable: define one macro that does it right, then use it. Example:
#define ROUND_UP(n, g) ((((n) + (g) - 1) / (g)) * (g))
#define ROUND_DWN(n, g) (((n) / (g)) * (g))
Regards,
Ulrich
More information about the dm-devel
mailing list